ID:83738
 
Lately I've been working on writing a library for using scripting languages from within BYOND games, which could be useful for both configuration and games like Exadv1's Console (or at least I'm guessing it could be, as I've never really played the game myself due to a major lack of documentation on excode). I'm hoping to make this very extensible while still remaining simple to use.

It's not quite finished yet, but I've created a demo here so that anyone can help test for bugs. Right now, the demo's only built in function is print. (Edit 1/30/11: Run the demo from the library instead.)

Here's an example of the language, which can also be found on the demo's hub page:
a=10;
if(a>0) {
i=0;
while(i<a) {
i+=1;
print(OddOrEven(i));
}
}
def OddOrEven(x) {
if(x%2) {
return "Odd";
} else {
return "Even";
}
}


Also note that the language is unique (or quirky?) in that functions, like variables, can be defined anywhere and are local to the block they're in, so for example you could have a function inside of an if statement.

Update:
-Else fixed for Tiberath ;)
-Also, I forgot to mention that unlike in DM, the ^ operator is used for exponents and the grave accent (`) is the binary xor operator.
def blah()
{
print(1);
blah();
}
blah();

Who needs while(1)?
edit: Aww, no dm tags in comments.

Nice job so far.
Yes.

Also note that the language is unique (or quirky?) in that functions, like variables, can be defined anywhere and are local to the block they're in, so for example you could have a function inside of an if statement.

You have no clue how many times I've wanted this in DM. Too bad the type system basically precludes such a feature.
Yay, someone else who puts their opening bracket on the correct line! Though your else is still a line below where it should be. ;)
Tiberath wrote:
Yay, someone else who puts their opening bracket on the correct line! Though your else is still a line below where it should be. ;)

His closing brackets are kinda odd, though; they should be indented once more!

IainPeregrine wrote:
His closing brackets are kinda odd, though; they should be indented once more!

They look alright to me =O

Proper code formatting. ;)
Oh well. I was going to link to a page with examples of all the different styles, including the correct way, which also happens to be the way I do it. However, I can't find that page, so instead I'll just yell HEATHEN! Burn the heretic!
Witch! Throw her off a cliff!

;)
I actually wrote a new language for Console (well, partially wrote it). My version of console (when I host it...rarely) is quite a massive upgrade to the previous versions. Ask Dever, console is like crack to him.


The new language isn't avaliable in my latest version, and I don't work on console that often, but when I do progress comes in large chunks. ExCode is a bit more powerful though, and I have a language reference.
Yeah, when it comes to bracket placement I'm pretty clueless. I personally prefer indentation like in Python and DM, but figured a C-like language would be easier to parse.
The program starts to hit into an infinitive loop and becomes non-responsive when a you call a function with no ending paranthesis.

print(
If you wait a while you get this runtime error from DM:

Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: ParseFunctionStatement (/n_Parser/n_Script/proc/ParseFunctionStatement)
usr: Haywire (/mob)
src: /n_Parser/n_Script (/n_Parser/n_Script)
call stack:
/n_Parser/n_Script (/n_Parser/n_Script): ParseFunctionStatement()
/n_Parser/n_Script (/n_Parser/n_Script): Parse()
Haywire (/client): Run()
Thanks, that's the kind of bug I'm looking for. It's fixed now, although I haven't updated the demo yet.
def count(n)
{
if (n > 1) {count (n - 1);}
print(n);
}

Gives a maximum recursion reached runtime error for any n > 1.
Thanks! I remember looking for that bug before and not figuring it out. Now thanks to you I've managed to find it, though it's not a simple fix.
I've fixed it and will be releasing the updated library soon. For higher values of n, it may be necessary to set world.loop_checks to 0.