Can you recommend a scripting language which allows me to easily parse "one-liner" types of scripts (they're just commands, really)?
For example, a C/C++ function which simply sets the value of a 2-dimensional vector (position, for example):
void SetVector(Vector2 &vector, float x, float y)
{
vector.x = x;
vector.y = y;
}
And in the scripting language, the entire script should be able to just be one line long. For example, this would be a script to set the components of vector "a" to 123.0f and 456.0f (x and y) (syntax of the language doesn't really matter, just as an example):
set_vector a 123,456
I'd use these short scripts to do simple things like change the position of objects during runtime (for debugging or other purposes), create simple config files for all kinds of entities which would go like:
bomb.script:
set_damage 1000
set_range 250
set_texture Data/Sprites/bomb.png
etc.
From a superficial glance, Lua, AngelScript etc. seem to be a little bit bloated for my simple needs (Although I must admit I haven't put tons of time into those two). Can you recommend something better?
Answer
As far as simple, "one-liner" scripts are concerned, Lua is a perfectly legitimate choice. Function binding is easy, even with the native API (though there are plenty of helpers for this). It's syntax is pretty easy to learn. Oh, and the runtime is tiny, if that sort of thing matters to you. You won't even have to include its standard libraries, so it'll be even smaller than the compiled static library.
Lua also makes a good data-description language, much like JSON or XML.
Also, don't cut yourself short in terms of room to grow. Right now, you may only want "configuration scripts." But you'd be surprised how easily you might want logic to start creeping into those configurations. Maybe you spawn certain entities based on game state. Or change the texture of something based on game state. Whatever.
Lua can handle all of these kinds of things quite readily.
It is much easier to have too much power and not use it, than it is to have less power and then suddenly need more. Lua's power will be there if you use it, and if you don't, then you won't care. It'll still be quick and simple.
No comments:
Post a Comment