I have come upon a problem with binding C++ and Lua. I have implemented a simple class system in Lua that makes me able to create an "instance" of a lua class from another lua file using
require 'classname'
m_newObj = classname() --"classname() creates a new instance
then I can access functions in m_newObj using
m_newObj:functionname(parameter)
This works perfectly fine, but I want to be able to access an instance of a lua class from C++ code.
Normally you can create access to lua functions in C++ using
lua_State* pL = luaL_newState();
...
lua_getglobal(pL, "functionName");
lua_call(pL,0,0);
But this only calls a function in a luafile, it does not call that specific function on a specific instance of the "class".
So basically what I want to do is
- get access to an instance of a lua class in C++
- call functions on specific instance
The reason why I want to do this is because I've discovered that in performance it requires a lot more to use C++ functions in lua than using lua functions in C++, So to be able to use lua to extend entities without having the lua code call a lot of C++ functions I need to get access to lua classes in C++ instead of getting access to C++ classes in lua.