[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Incorrectness in the manual
- From: Egor Skriptunoff <egor.skriptunoff@...>
- Date: Mon, 4 Sep 2017 07:13:59 +0300
Lua manual contains very misleading incorrectness.
According to manual, "luaL_setfuncs" SHARES upvalues among all the registering functions:
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).
Please fix the manual.
"...all functions are created sharing nup upvalues, which must be previously pushed on the stack..."
"...all functions are created having its own independent upvalues initialized with the same nup values, which must be previously pushed on the stack..."