lua-users home
lua-l archive

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

On Sat, Oct 2, 2010 at 6:26 AM, Sylvain Fabre <> wrote:
>  Hi all,
> We are using extensivly the luaL_Reg structure to handle methods to be
> applied on C objects.
> One drawback (as far as i know), is that the structure does not allow the
> storage of additionnal datas that can be used by callbacks for example
> So ideally, would it be possible to have something like this :
> typedef struct luaL_Reg {
>  const char *name;
>  lua_CFunction func;
>  void  *udata;
> } luaL_Reg;

You can always extend luaL_Reg to some kind of custom data structure.
I did the same thing for C++ bindings where I wanted to differentiate
between function calls, and settable / gettable attributes (e.g.
obj:method() v. obj.attr = 10).  For you case though, it sounds like
you simply want upvalues for you functions, which you can create with
lua_pushcclosure ( ).  If it
makes sense in your code to have a special data structure for the
functions, their names, and the upvalues, then go for it.  I don't
think it's unusual to extend luaL_Reg, but it's not really something
that needs to be changed in Lua itself.  This kind of abstraction is
more for a level above Lua IMHO.