lua-users home
lua-l archive

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


> Hi!
> 
> Lua manual contains very misleading incorrectness.
> According to manual, "luaL_setfuncs" SHARES upvalues among all the
> registering functions:
> (quote)
> When nup is not zero, all functions are created sharing nup upvalues, which
> must be previously pushed on the stack on top of the library table.
> (end of quote)
> But that's not true.
> Actually, each function gets its own separate upvalues.
> These upvalues are initialized with the same values, but upvalues are NOT
> SHARED between functions.
> 
> This is very confusing.
> For example, one could think after reading the manual that using
> "luaL_setfuncs" it is possible to register set of two functions: "set" and
> "get" sharing the same upvalue, which is being set and get.
> But this direct solution will not work.  Instead, some workaround is
> required (such as using a container holding the shared value).

Actually, for your interpretation, one would need to find a way to
push an upvalue in the stack. Did you really understand that way?
Has someone ever done?

-- Roberto