C++ Inheritance in Lua

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • C++ Inheritance in Lua

      So, I decided to take up the challenge Rez. mentioned in the Lua Scripting Chapter, to enable Lua classes to inherit from C++. I decided I would go with the approach that when Lua requests for C++ inheritance, it would set up a metatable for the C++ class. There is only one problem, I want to iterate through C++ member functions, store them in a vector/list and register them one by one. Do you guys know any way I could be able to do this?
      "I'm here to kick ass and chew bubble gum and I'm all out of gum."- Duke Nukem
    • RE: C++ Inheritance in Lua

      There's no way you can iterate through C++ functions from within the code. The way I've handled that in the past is with a post-compile script that spidered through the C++ code, extracted the functions, and generated the glue file. tolua++ does this by using comment tags in the source files.

      In my own projects, I just manually register the functions. In general, I try to have a very thin interface between Lua and C++ so I have very few functions that are actually exposed to Lua.

      If you look at the GCC codebase in ScriptProcess.h/cpp, you'll see how I did it. That's pretty much what I do in my own engine as well.

      -Rez