Eval strings to commands?
BlitzMax Forums/BlitzMax Programming/Eval strings to commands?
| ||
Hi people. There his any way to eval strings like JavaScript to execute the commands inside the strings? for example Local aa:String = "Hello world" Local bb:String = "Print aa" Eval(bb) |
| ||
No there is not (nothing official anyhow). |
| ||
It's possible in Javascript, Perl, Lua, PHP and any other scripting language because it's a scripting language. It gets interpreted at runtime. BlitzMax doesn't allow this because you have to compile your code before being able to run in. |
| ||
Note that there are LUA modules for blitzmax that allow you to add LUA scripting to your Blitzmax program -- but it is a seperate languatge, you wouldn't be able to run straight blitz code through it. |
| ||
thanks for the answers. i see how to implement the LUA scripting feature. |
| ||
write your own interpreter and share it. that would be awesome ;) |
| ||
Perhaps with tons of function pointers and variable pointers, and reflection you could maybe parse strings of BM code at runtime.. or a simplified varient of the language that satisfies your needs. So get object names from the text and reflect on objects to find that object. And when you see Print, you set an execution pointer to the Print function. And then pass it that object. |
| ||
I remember i once, long time ago, wanted to do the same, and.. I did neither know there are pointers nor there's reflection ... :Select Lower input Case "Print" Case "IncrAmmo" Case "DecrAmmo" .. End Select Thats aweful! |