Register C++ function in Lua?

后端 未结 4 1046
小蘑菇
小蘑菇 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:23

    You can not use a method of a class as a normal function, unless it is declared static. You have to define a normal function, which finds out what object you want the method to be called in, and then call the method.

    The main reason it's not possible to use a class method as a callback from a C function (and remember that the Lua API is a pure C library), is because the computer doesn't know which object the method should be called on.

提交回复
热议问题