Sending variable pointers back and forth between C++ and Lua?

前端 未结 3 693
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 02:22

I am looking for a way to transfer the variable addresses back and forth between C++ and Lua. For instance, transferring an object from C++ to Lua and do some processing, th

3条回答
  •  生来不讨喜
    2020-12-15 02:51

    See the article at the Lua user's wiki about binding code to Lua. There are several techniques for making a C++ object useful from the Lua side of the fence that range in complexity from just letting Lua hold an opaque pointer that it can't directly use, to a full wrapping exposing all C++ methods and potentially even allowing the object to be extended with methods written in Lua.

    For simple functional libraries written in C, it is fairly easy to write your own binding by hand using the Lua API to move between the Lua stack and your library's functions.

    For an object based system, it is a lot more work to do by hand, so one of the binding tools listed on that page will make your life a lot easier.

提交回复
热议问题