BP Scripting language module.
BlitzMax Forums/BlitzMax Programming/BP Scripting language module.
| ||
Update (5 Months later >_>): Having noticed someone posting about this, I've updated this topic with a new link to an updated version, which is more optimized and includes the Switch statement. Please be aware that no updates are forthcoming as this module was ditched shortly after posting the first version of this topic, in favour o a more optimized and organised version. The new download link is: www.binaryphoenix.com/?action=software&step=view&id=11 Its also in the toolbar here: http://www.blitzbasic.com/toolbox/toolbox.php?tool=169 Old Post: Well I've been developing an rpg engine recently (worklog - http://www.blitzbasic.com/logs/userlog.php?user=7531&log=631) and while I was designing it I was working on a scripting language for it, i fiqured some people might like it so im releasing a module for it, its pretty much the same thing im using in my engine but all the game specific stuff has been stipped out of it. It may also be of some help to people who want to develop there own scripting language as its a pretty good base but unfortunatly its not particualy fast. Lol the fact that it wasent designed to be released explains why it dosent have a proper name XD. Heres a one of the examples supplyed with the exe to give you an idea of what it is. BPScript /* ============================================================================= * Example 03 - Basic threading * Copyright (C) 2005 Binary phoenix * ============================================================================= */ //----------------------------------------------------------------------------- // Entry point for thread 1 Function Example03a() { // Local variables Var i; // Say that we're starting Print("Thread 1 is starting!"); WaitMS(4000); // Print a message Print("Thread 1 message 1!"); WaitMS(8500); // Print a message Print("Thread 1 message 2!"); WaitMS(300); // Say thread 2 testing 20 times with a 0.2 // second pause in between For(i=1;i<=10;i++) { Print("Thread 1 illteration "+i); WaitMS(200); } // Say that we're ending Print("Thread 1 is ending!"); } //----------------------------------------------------------------------------- // Entry point for thread 2 Function Example03b() { // Local variables Var i; // Say that we're starting Print("Thread 2 is starting!"); WaitMS(500); // Print a message Print("Thread 2 message 1!"); WaitMS(800); // Print a message Print("Thread 2 message 2!"); WaitMS(1000); // Say thread 2 testing 10 times with a 1 // second pause in between For(i=1;i<=10;i++) { Print("Thread 2 illteration "+i); WaitMS(1000); } // Say that we're ending Print("Thread 2 is ending!"); } Bmax source Rem BPScript - Scripting language Example02 - Basic threading Copyright (C) 2005 Binary phoenix Coded by Helios (Aka. Tim Leonard) For more infomation, support and updates please go to BinaryPheonix.com End Rem ' Import modules Import BinPhx.BPScript ' Simple command set (you can register commands seperatly to each VM, but this .. ' .. is easier as all vm's automatically register all command sets) Type TExample01CommandSet Extends TVMCommandSet ' Register the commands Method RegisterCommands() RegisterCommand("Print",C_Print) RegisterCommand("WaitMS",C_WaitMS) End Method ' Simple print function Function C_Print(Thread:TScriptThread) ' Unfortunatly the GetParam* functions get the parameters in reverse order ' to get the parameters in the correct order use the GetParamAbs* functions. Print Thread.GetParamAsString(0) End Function ' Simple wait function Function C_WaitMS(Thread:TScriptThread) Thread.Pause(Thread.GetParamAsInt(0)) End Function End Type ' Install command set by creating a new instance of it New TExample01CommandSet ' Create a virtual machine to run the script on Local VM:TScriptVM = New TScriptVM ' Load the first thread and invoke its functions Local Thread:TScriptThread = VM.LoadScript("Scripts\Example03.bp") Thread.InvokeScriptFunction("Example03a",False) ' Load the first thread and invoke its functions Local Thread2:TScriptThread = VM.LoadScript("Scripts\Example03.bp") Thread2.InvokeScriptFunction("Example03b",False) ' Run until the thread has finished Repeat ' Run all threads in the VM with an infinate timeslice VM.RunThreads(-1) ' Check if the thread is finished if so quit If (Thread.IsActive = False) And (Thread2.IsActive = False) Then Exit Forever Unfortunatly the bmax source is badly missing an abstraction layer to make it easier to use but it should be good enough to use. Feel free to poke around in the source and make changes and post any tweaks you think are usfull (it could use a LOT of tweaking i know!). And if you dont like the syntax try modifying the lexer in the TScriptCompiler type its very easy to change it to a basic style if you prefer. DOWNLOAD LINK - http://www.savefile.com/files/6012948 And heres a list of supported operators / statments, just because im so nice :P. Operators: -- ++ <<= >>= %= &= |= ^= #= /= *= += -= != == >= > <= < << >> % & && || | ~ ! ^ # / * + - Statments: Function Variables Constants Return While For If Break Continue Function calls Mutexs Assignments Expressions |
| ||
Rejoyce Ya, Nice one - just downloaded now - going to have a look at this now! |
| ||
Downloaded it. I'm actually thinking about a game that will need quite some prototyping to test stuff for what a script language would be really usefull (especially the AI prototyping). Thank you for contributing that. |
| ||
Downloaded it. :) I hope I can use this for my Bomberman game ;) Nice RPG. Keep it going. |
| ||
Just noticed someone posting about BPScript, decided I may as well post a link to the updated version (its now named MicroC), its been optimized a bit and the Switch statement is now in it. Esentially its still pretty much the same API. Don't expect any updates though, this scripting langauge was ditched a while ago in favour of a rewriting it with a more optimized and organized system. You can download it here: http://www.binaryphoenix.com/?action=software&step=view&id=11 |
| ||
Thank you for letting us know of that :-) And sorry if I shouldn't mention your great scripting language for those who think that LUA is over their head ^^ |
| ||
Thank you for letting us know of that :-) No problemo. And sorry if I shouldn't mention your great scripting language for those who think that LUA is over their head ^^ ^.^, your welcome to if you wish. It's just this isn't the most optimized of scripting languages, it was made more as proof-of-theory than anything else. |
| ||
That might be. But its better to have a little slower and understandable scripting language than a monster that can't be tamed, isn't it? :-) |
| ||
True I guess. I may rewrite this when I have the time so its faster, cleaner and supports some other features. I'm actually working on one now which is a lot more grander, shame its in C# :(. |
| ||
I love it! Your code is very clear! Is there an formular EBNF description of MicroC? What are "pesky data types" ? cu olli |
| ||
I love it! Your code is very clear! Really? I always hated that commenting style as its badly over-commented, my code is much nicer now'a'days :P Is there an formular EBNF description of MicroC? Nope, but I can write one if you want. What are "pesky data types" ? Just me being stupid, by data types I was refering to the fact that MicroC is typeless, and thus you don't have to declare the data type of a variable (string, int, ...etc). |
| ||
The identifier convention is very clear. Your comments are ok and not "over-commented" :) Is MicroC a language idea of you? I can't understand how to create a so complex language without EBNF. I must use regular expressions yet for a simple lexer :) Hmm, typeless is a quasi standard of such scripting languages, but I hate it. Look at PHP. It is very painfull to debug big codes but for simple RPG scripts is that nice. Is there chance to program a compiler for machine code? I have a small handheld here and there is no high level compiler for it. Only a assembler. cu olli |
| ||
Is MicroC a language idea of you? Not really so much an idea as an evolution, it just grew out of my requirements for the RPG engine I was designing (now ported to C#). I can't understand how to create a so complex language without EBNF. I must use regular expressions yet for a simple lexer :) Its quite simple really, all you have to do to convert the script to a tokenized format is to go through each character in the script at a time and create a token for it or parse the script further in the case of 1+ charcter keywords, identifiers and literal values. Just look at the bottom of the compiler.bmx file, all the lexing stuff is implemented there. Hmm, typeless is a quasi standard of such scripting languages True, I just couldn't think of features to put in a list >_>. Is there chance to program a compiler for machine code? I have a small handheld here and there is no high level compiler for it. Only a assembler. Possible, though would require some major restructuring, as the language's compiler, lexer, parser and code emitter are all stored in the same class and are pretty in-interchangable as it wasn't designed for multiple back/front ends in mind. For something like that starting from scratch would probably be a good idea, it's quite easy to get a simple language up and running in a few days once you get the hang of it. |
| ||
Looks good, not too hard also. I would definitely use this over LUA (i dont like the syntax =/). Im wondering though, how would I insert a variable into a string? I havn't tried yet, but none of your samples demonstrate that(?) |
| ||
Im wondering though, how would I insert a variable into a string? I havn't tried yet, but none of your samples demonstrate that(?) Do you mean how you would insert a value into a string? If so you can use the SetGlobalAs*/GetGlobalAs* functions of the TSciptThread class. |