Jump to content

Recommended Posts

Posted

'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

 

Posted

Yes I've read that, but the class doesn't do the loading of LUA file and instancing of for object

I'm using Interpreter::Push (which is tolua_pushusertype(L, o, o->GetClassNameStr().c_str())

But my class is for example Class A : public Entity, but my script using Script:<NameSpace> (same format as Leadwerks).

I need a function from an allocated Entity 

1) Load 1 Lua file  (Interpreter::ExecuteFile) (Which is using Script::<NameSpace> function).
2) 'Connect' for each entity  to the loaded lua (I don't want to load 1000 times the same lua code).
3)  Ability that each entity have its own variable.

 

 

Posted

Doesn't this just give "Error failed to..." every time? you're printing the error when the Interpreter::ExecuteFile method returns true..

But yeah Josh is right, Entity::SetScript(const std::string& path); is what you're looking for.

Posted

Yep.  There is no script loading function, because there is no script object.

My job is to make tools you love, with the features you want, and performance you can't live without.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...