I have come across the need to use a scripting engine for my C++ game, but after experimenting with many languages since the last few days, nothing has truly stood out as the obvious choice for a language and/or binding library.
I would like have the ability to
- call methods of a specific Game instance from within the scripting language,
- call arbitrary functions in the scripts from C++, and
- test for function existence in the scripts using strings.
Lua looks nice, but I'm unsure of its ability to do 1 and 3. Python and Boost::Python are great, but the same applies. Regardless, here's an example of an ideal implementation.
C++
class Game
{
...
void printNumber(int arg);
};
int main( )
{
Game *game = new Game();
// Make method available to script
functionRegister("printNumber", game->printNumber);
// Test and call function in script
if ( functionExists("greet") )
functionCall("greet", "Hello world");
}
Script pseudocode
function greet( greeting )
print( greeting )
game.printNumber( 42 )
end
The output may be
Hello world
42
Is there a language and library that will pull this off?