Jump to content

LUA CPP "how to" 3/7

Charrua

780 views

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.

 

Next, Home, Previous



0 Comments


Recommended Comments

There are no comments to display.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   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...