lua-users home
lua-l archive

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

> > Now as I try to
> > create a macro that would create the Get/Set functions for the
> > members of some C++ class, I find that a single macro cannot both
> > declare the functions and register them (or include them in the table
> > that is passed to luaL_openlib).

I think this would do the trick:

#define GET(x)                            \
static void LuaGet##x(lua_State *state)   \
{                                         \
  /* ... */                               \
static int dummy##x = Register(x, LuaGet##x);

Register will then call lua_register, taking care of opening Lua if this
was not done already (since these are called in an undefined order (IIRC).
For this, a static boolean value in Register would take care of what
should be done before the registration so it's done only once.
Yoh won't have much choice to set the name known to Lua to something else
though, unless you want to use GNU extensions:

static int dummy##x = Register(MyName #x, LuaGet##x);

I think this would work, but I can't test it now...

Vincent Penquerc'h