Guppy Posted September 13, 2014 Share Posted September 13, 2014 Entity->CallFunction comes in two flavors, one that seems aimed at collisions and one that passes an Object pointer. I'm not entirely sure how I'm supposed to use this to pass data to the function I'm calling, I can set a void pointer as "userdata" which isn't terribly usefull - the source claims to export it to lua but the documentations says it's not exposed in lua. Is it possible to use this to pass a table to lua? and failing that can I somehow convince CallFunction to pass along the information that I've pushed a table onto the stack? Right now I'm resorting to putting the table into a global, which is not really ideal. Now I can sidestep using CallFunction by doing Leadwerks::Interpreter::GetGlobal("Player:Test"); lua_pcall(Leadwerks::Interpreter::L, 1, 0, 0); Unfortunately I've no idea what Global to use ( in the above I'm trying to target the Test function inside Player ) Quote System: Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k Link to comment Share on other sites More sharing options...
Josh Posted September 14, 2014 Share Posted September 14, 2014 bool Entity::CallFunction(const std::string& name, Object* extra) { if (component==NULL) return false; bool success = false; //Get the component table int stacksize = Interpreter::GetStackSize(); //Get the global error handler function int errorfunctionindex = 0; #ifdef DEBUG Interpreter::GetGlobal("LuaErrorHandler"); errorfunctionindex = Interpreter::GetStackSize(); #endif Push(); Interpreter::GetField("script"); if (Interpreter::IsTable()) { Interpreter::GetField(name); if (Interpreter::IsFunction()) { Interpreter::PushValue(-2);//Push script table onto stack if (extra!=NULL) { extra->Push(); #ifdef DEBUG errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1); #endif success = Interpreter::Invoke(2,0,errorfunctionindex); } else { #ifdef DEBUG errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1); #endif success = Interpreter::Invoke(1,0,errorfunctionindex); } } } Interpreter::SetStackSize(stacksize); return success; } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.