[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ::className and ::member in luna.h
- From: "James Dennett" <james.dennett@...>
- Date: Mon, 7 Jul 2008 22:27:24 -0700
On Mon, Jul 7, 2008 at 10:18 PM, Ry Lowry <rylowry@gmail.com> wrote:
> 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.
There's nothing special about those names to C++. They're just
variables defined in the program, static members of the type T by some
convention. Luna could have used a different set of names just as
well.
-- James