🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Is this a scripting language out there?

Started by
7 comments, last by smr 19 years, 11 months ago
I was reading a thread at Allegro.cc, and somebody suggested a scripting language with the following syntax. (or lack thereof)

234,9,1,90 // 234 == blit. blit object type 1, id 90, onto surface #9
41,99,88 // move value 88 into variable #99
80,"Hello" // printf("Hello")

Each number would be a function call, and then the following numbers would be parameters. Like normal. What's interesting about this idea is that it's eye-bleeding simple. Simple to write, simple to `interpret`, and easy to find syntax errors. It'd be blazing fast. Even more so if a game had an interpreter to translate from ASCII to some bytecode. Is this already out there? I'm perfectly happy with Lua, but I'm interested in speeding up my engine. It'd be even better if I could find it already created. heh'
Advertisement
Thats actually how must scripts are compiled. Say we have a C like script...we break it down into an ASM like script. Then simply break that down into numbers. Each function has an opcode, and each variable has a type.

So we have
OPCODE NUMVARIABLES VARIABLETYPE VARIABLE

So lets say our opcode was 1 (for add), our variables were its (intcode 2). A call might look like this
1,2,2,45,2,85

The reason for the commas is so you can tell where the next variable is. If you didn't have them:

12245285

Can you tell where the variables are? Are they one or two characters long?

You get the idea.

Most scripts are broken down into this opcode variable code structure upon compilation into their binary form. Its just faster than parsing a C like, or even ASM like script at run.

Check out Game Scripting Mastery. It is explained really well in there.
Quote: Original post by Kanzure
...it's eye-bleeding simple. Simple to write, simple to `interpret`, and easy to find syntax errors...


It would also be eye-bleeding difficult to read and debug.

I'm also not so sure it would be simple to write. Rather than typing a function name, you would have to remember the numeric value of every function in the script.

- Mike
Quote: Original post by Kanzure
I'm perfectly happy with Lua, but I'm interested in speeding up my engine.


Isn't Lua used in a lot of commercial titles? Are you sure it is your scripting engine that is degrading your game's performance?

I should've been more clear. I'm interested in seeing the (or any) speed differences between lua and 'my' idea.

Like I said, you could have an interpreter to interpret to the 'opcode', so there really could be any number of syntax to translate to this 'number based' scripting language.
If you've got the knowledge and time to make your own scripting engine, do so. It will most likely come out to be faster than Lua because Lua is general purpose. Your engine will be specific.
You aren't doing anything new at all. I hate to break it to you man. It isn't really "your idea". What you are doing is saying "why even write a parser to create a binary file...why not just write it in the binary syntax?" And as mentioned before...because its impossible to debug and remember. Thats exactly why languages were invented. Most scripts that are compiled end up going from C syntax to ASM to the same numbered binary type file...because its faster to parse numbers than a whole scripting language in realtime loading.

But here is another idea if you really feel like implementing it.

If you want to make it even faster, dont have things like "Hello!", just make a string table. So like this:

80, 1
... (bottom of script contains string table)
1
Hello!

So we print stringtable 1. At the bottom we see our stringtable has one entry, and is "Hello!". Easy enough. That way when you take the input from the script, all you need is numbers.



Yeah. Anyway, I really recommend you read Game Scripting Mastery if you can. You will see your idea is actually pretty mainstream. Its just better to do something that includes how many variables there are and the variable types for error checking, and to remove \n and comments. So instead of what you originally had, it could be
Blit Objects Code: 1
Surface Code: 2
INT: 3
Variable: 4
String 5


234,3,2,9,1,1,3,90,41,2,4,99,3,88,80,1,5,1
[VARS]
99
...
X
[STRINGS]
1
Hello

There you have your binary file, a variable table with 99 entries, and a string table with one entry.

Good luck.
If you want to do that, and you like lua, why dont you just compile your scripts? Lua will load and run bytecode or source format scripts.
You would see minimal, if any execution speed improvement. Lua is compiled down to bytecode, so you end up running essentially what you've posted.

This topic is closed to new replies.

Advertisement