Shadoh Posted April 28, 2014 Share Posted April 28, 2014 Hi guys I'm trying to mix c++ with Lua. But cant figure out how to get them to interact, how would I do the following Send an object, such as a camera in to lua, or change the reference to a camera (that's stored in c++) from lua Send a value to/from lua Thanks Quote Link to comment Share on other sites More sharing options...
shadmar Posted April 28, 2014 Share Posted April 28, 2014 If camera and world was created in c++ you can do something like this to pick it up in lua : local world=World:GetCurrent() for i=0,world:CountEntities() do if world:GetEntity(i):GetClass()==Object.CameraClass then self.camera=world:GetEntity(i) break end end Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Shadoh Posted April 28, 2014 Author Share Posted April 28, 2014 Ok, that's a start. But looks like I'll have to convert my game entirely to LUA to get more control .. at-least until there's more documentation or something Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 28, 2014 Share Posted April 28, 2014 From Lua to C++ http://www.leadwerks.com/werkspace/topic/6887-communicating-from-lua-to-c/page__hl__communicating Quote Link to comment Share on other sites More sharing options...
shadmar Posted April 28, 2014 Share Posted April 28, 2014 You can also store data on entities which can be set/retrieved from both ends, using SetKeyValue GetKeyValue. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted April 28, 2014 Share Posted April 28, 2014 Do you have examples of what you are looking to do? Mixing between them via the way Aggror mentions is sort of a pain but once you have the objects setup it's slick to use them. Doing it via shadmar's method he mentions gets basic types from C++ to Lua and is easy to setup but again, it's basic types. I think mixing is a pain. Something to test is what happens when you use SetUserData() in C++ and GetUserData() in Lua. SetUserData() generally let's you pass a class pointer casted as void*, but would be interesting to test what you get back in GetUserData() and how to use it in Lua. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 28, 2014 Share Posted April 28, 2014 To be honest I never tried the ways that were suggested in that topic. They seemed like a lot of work. At that moment, setting and getting keys was the simplest solution and was enough for my scenario. When you go more advanced the suggested solution in that topic are the way to go. Quote Link to comment Share on other sites More sharing options...
Shadoh Posted April 28, 2014 Author Share Posted April 28, 2014 I have no particular thing I want to do, my projects at the moment are basically testing what I can/can't do I'm just going to use a Lua project I think. That way any global variables and such are easily accessible from all my code. In this case, I was making a day/night cycle simulation, and needed to access the camera (to SetClearColor) from c++ and control the camera from a FreeFlyCam object written in Lua. On another note: is there an "option explicit" (from VB) equivalent in Lua that forces explicit declaration of variables? I keep mis-typing my variables, and spending ages trying to debug the original cause that's not obvious at all. Quote Link to comment Share on other sites More sharing options...
Rick Posted April 28, 2014 Share Posted April 28, 2014 That way any global variables and such are easily accessible from all my code. this makes me sad On another note: is there an "option explicit" (from VB) equivalent in Lua that forces explicit declaration of variables? I keep mis-typing my variables, and spending ages trying to debug the original cause that's not obvious at all. No. Welcome to scripting Finding specific LE entities between Lua and C++ is easy. Use SetKeyValue()/GetKeyValue() to give some kind of ID and your're good to go. Then just loop over the map's loaded entities and check that key value to see if it matches what you are expecting. I think what some of us thought you were asking is how can you get your own custom C++ class exposed in Lua, which is more work. Quote 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.