One of the things I want to do for my game is have my player class and other classes call a specific function say update(delta_time) from a script. There would be a different script for each different character that the player might be. This means I would have multiple scripts that share the same function names becuase my class in c++ would just want to call update(delta_time) from the script. Currently to get this working in each script i put the prefix of the character name infront so now the function names are essentially different. Then when an instance of the class is created i set a variable in it to the name of the class. Then to call the function I just add the prefix of the name to update so it calls the function based on the name of the character.
example
2 scripts
bob.nut
function bobupdate(time)
{
//do stuff here
}
carl.nut
function carlupdate(time)
{
//do stuff possibly different than bobs
}
Then in c++ the update function for the class looks like this
void Player::update()
{
//call a squire function
char update[64];
sprintf(update,"%supdate",name);
SquirrelObject root = SquirrelVM::GetRootTable(); // gets the global scope
SquirrelObject upd = root.GetValue(update); //fetches the function from the root
SquirrelVM::BeginCall(upd);
SquirrelVM::PushParam(1);
SquirrelObject retval = SquirrelVM::EndCall();
// do more stuff below
}
This works fine for what I want but seems like there should be something better?
-Matt
p.s. Also hopefully tomorrow I will post a small tutorial of some of the things I have been fidling with, just want to clean it up.
pps Also on the documentation at least the online one in the Create C function
sq_newclosure(v,f,0,0); //create a new function
sq_newclosure only takes 3 parameters not 4