c++objectlualua-apilua-userdata

Using C++ objects in Lua scripts


How I can use C++ objects in lua script?

example class:

class cMyClass
{
 int a;
 void myTest(int b){};
}

cMyClass MyObject;

example using in lua(is what i need):

MyObjectLuaName.myTest(7);
MyObjectLuaName.a=12;

Thanks!


Solution

  • "Use C++ Objects in Lua" - for me that shouts for an "userdata" object!

    http://loadcode.blogspot.de/2007/02/wrapping-c-classes-in-lua.html (this one is nice) http://rubenlaguna.com/wp/2012/12/09/accessing-cpp-objects-from-lua/

    That does exactly what you need.