lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello all,

I am a new comer to Lua.  Currently I am working on a simple C++ app
that renders a cube to the screen using OpenGL, and exposes cube
functionality to Lua.  I have created a class to represent the cube,
and I have been experimenting with it in various ways.  Before I
worried about doing anything object oriented from Lua, I created a few
procedural functions to modify the cube.  During that phase I created
and destroyed the Cube manually in my C++ code.  However, I am now
moving on and attempting to learn how to expose my Cube class to Lua
so that it can be used in an OO style from a script.  To accomplish
this, I have been studying the Luna class provided at
http://lua-users.org/wiki/SimplerCppBinding.

Using luna.h as a reference, I have managed to create a "new" method
for the Cube that Lua can call.  All of the Cubes that are getting
created in the Lua script are also being automatically deleted when
lua_close() is called (thanks to the "__gc" metamethod).  However,
both the "new" and "destroy" methods that I created were hand built
for the Cube class.  To complete my learning exercise, I would like to
create a set of template functions that essentially replicate what
luna.h already does.

However, as I was going through the code, I came across the following
lines which threw me off:

luaL_newmetatable(L, T::className);

for (RegType *l = T::methods; l->name; l++) {

I did not realize ::className and ::methods were available at all.  I
have a C++ book that covers programming with templates, but I couldn't
find anything mentioned about either "className" or "methods."  Also,
my Google searches have not turned up anything that clearly explains
these.  How much information is available?  Are there any other calls
that can be made?  Where can I turn to learn more about ::className
and ::methods?  How did the author of luna.h likely learn about these?

I tried asking this question on a forum for general C++ questions, but
I have not received a response that has helped me.  However, it is
clear that someone in the Lua community understands what's going on.
If anyone can point me in the right direction I would be grateful.  It
would certainly help me to more fully understand the workings of
luna.h!