LUA CPP "how to" 3/7
2) How to send objects created by Cpp code to LUA
Here is a way of sendign CPP created objects to LUA scripts as GLobal Variables, so
any LUA script on you map can simply use it.
I create on cpp: window, world and context and pass them this way:
System::Print("sending objects...."); stacksize = Interpreter::GetStackSize(); Interpreter::PushObject(window); Interpreter::SetGlobal("window"); Interpreter::PushObject(context); Interpreter::SetGlobal("context"); Interpreter::PushObject(world); Interpreter::SetGlobal("world"); Interpreter::SetStackSize(stacksize);
so simple, only after knowing it!
i modify App.lua to:
not define window, world and context and use them as:
if window:Closed() or window:KeyDown(Key.Escape) then --logFile:Release() return false end --Update the app timing Time:Update() --Update the world world:Update() --Render the world world:Render()
note : that's a fragment of App.lua main loop (function App:Loop() )
instead of the default:
if self.window:Closed() or self.window:KeyDown(Key.Escape) then --logFile:Release() return false end --Update the app timing Time:Update() --Update the world self.world:Update() --Render the world self.world:Render()
with tuts 1 and 2 we has ways of sending Leadwerks objects (any Leadwerk's object) to LUA and retrieving LUA objects.
Objects sent to lua, will be global to any function on any LUA scritp.
0 Comments
Recommended Comments
There are no comments to display.