'm using the C++ SDK and lua for small objects code. I need to create the entities from C++ and later use the bool Entity::CallFunction(const std::string& functionName, Object* extra)
How to 'bind' on script lua to an entity ? it looks that Interpreter is using tolua++, but I can't figure how to load the .lua properly to the object
// Create 100 special entity
std::vector<Entity*> list;
for (int i = 0; i < 100; i ++) {
Entity* entity = new MyEntity();
entity->AddToWorldTable(true );
list.push_back(entity);
}
// Load special script (But not working, object not callable).
Interpreter::NewTable();
Interpreter::SetGlobal("Script"); // Must Script. Don't change that, because the script are prefixed with Script:myFunction
if (Interpreter::ExecuteFile("MyEntity.lua")) {
System::Print("Error: Failed to execute script \"" + it + "\".");
}
for (auto&it : list) it->CallFunction("OnSpecialFunction")
Script Lua
function Script:OnSpecialFunction()
print self
end