🎉 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!

engine custom script language

Started by
9 comments, last by Ivica Kolic 2 years, 4 months ago

Back in a day when I was working on custom engines I had to make my own scripting language because I couldn't find any that can run multiple scripts at once (if I have 32 threads I want to be able to run 32 scripts at once). At the time Lua was popular, but to do that you had to instantiate 32 separate instances of Lua which was crazy. I see that things didn't change too much since then.

So I took ANSI C grammar and removed everything regarding “struct" from it to make it more scriptable (only base types allowed: int, float, char, pointer). Used Flex and Bison to create compiler (parsing tree) and then did 2 passes to produce compiled output which is nothing than series of integers and constants. Each integer is just and index to a function in an array of function pointer. Basically my interpreter was nothing but array of function pointers and I would go through compiled script (which is array of indexes) and called appropriate function at that index (each function takes params from the stack and returns output on stack). It is blazing fast (even though it has double stack operations).

Here is a picture of it working in my old engine (two virtual terminals: in one you program the other)

This topic is closed to new replies.

Advertisement