Lua/C++ binding from scratch

Viewed 4230

I'm new to Lua, and trying to understand some of the fundamentals. Something I want to understand is binding Lua to C++ instances.

I am not interested in third party libraries, I want to understand this at a more fundamental level - thanks :)

Here are my questions:

  1. My assumption based on what I have read, is that Lua can only bind to static C functions. Is this correct?
  2. Does that mean that to bind an instance of a C++ class, I'd first need to write static functions for each method and property getter/setter I want, accepting an instance pointer as a paramter.
  3. I'd register these functions with Lua.
  4. I'd pass Lua a pointer to the instance of the C++ class.
  5. From Lua I'd call one of the registered functions, passing the C++ instance pointer.
  6. The static function dereferences the pointer, calling the equivalent method.

Does this make sense? Or have I gotten something wrong?

Thanks for reading this far.

1 Answers
Related