Register C++ function in Lua?

后端 未结 4 1045
小蘑菇
小蘑菇 2021-01-07 07:39

I am trying to register a c++ function in Lua.

But getting this error:

CScript.cpp|39|error: argument of type \'int (CScript::)(lua_State*)\' does n         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 08:03

    You cannot directly register a C++ non-static member function in Lua using just the basic Lua C API.

    However, any of the various mechanisms that exist for easily associating C++ code with Lua will allow you to do so. toLua++, SWIG, Luabind, etc. If you're serious about using C++ objects with Lua, I suggest picking one of those and using it, rather than writing your own version. I personally use Luabind (most of the time; SWIG has its place in the toolbox), as it is the one that doesn't have some form of code generation. It's all done purely in C++, so there's no pre-pass step that generates a C++ source file.

提交回复
热议问题