I'd like to embed lua to allow scripting in my C++ application. In particular, I have two structs which I'd like to pass as arguments to a given lua function. One will be read-only, the other will be read/write. Highly simplified examples of these structs follow:
struct inData
{
int x;
int y;
//many other fields follow
};
struct outData
{
int a;
double b;
//other fields follow
};
Both of these structs are created in the C++ code and will be processed there both before and after calling the lua functions. How can I pass these structs to a lua function such that the function can do things like this:
if(inData.x > 5) then outData.a = 1 end
and have the outData instance actually retain the changes after returning from the lua function?
boring + boilerplate + multi-language = SWIG.
http://www.swig.org/Doc1.3/Lua.html#Lua_nn13
You could also create a Lua table that reflects this same data structure for passing information between C and Lua.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With