2011年9月3日 Xavier Wang <weasley.wx@gmail.com>: > Hi all in list, hi Roberto :) > > I have written a patch for Lua 5.2-beta, for support multi embedded > values for lua's userdata. this used to deprecate the env table of > userdata. this patch allow you embed more than one value to a > userdata. it's very useful to implement light-weight array, or > linked-list or show the dependency of objects. > > Reason: > > In Lua 5.1, we have env-table for function and thread and userdata. > for function and thread, it holds all its 'global' variables. but for > userdata, it's just a 'uservalue', used for contain user defined > values. but In Lua5.2, we used _ENV to replace env table, but the > userdata env is remained because it's useful. but the functional of > userdata's env is to weak: it can only contain Table, if you want to > link more than one value with your userdata, you have to put them into > the env *table*, but a table is to heavy (56 bytes, vs TValue has only > 8 bytes when enable the NaN trick), it's not suit for the embedded > devices, etc. > > So I added four new api into Lua5.2-beta, they are: > > void *lua_newuserdataev(lua_State *L, size_t size, size_t extravalues); > void lua_getuservalueev(lua_State *L, int idx, int vidx); > void lua_setuservalueev(lua_State *L, int idx, int vidx); > int lua_getuvcount(lua_State *L, int idx); > > you can use these new api to create a userdata with extra values (ev > == extra values), you can access these values, or query the count of > extra values. vidx accepted 1-based index to extra-values, and if vidx > is negative, is means the last 1-based value to the first one. 0 is > always a invalid index (just the same rules of lua stack). > > the attachment is the patches to lua-5.2-beta, and a test module named > array, and a working binary for Windows. > > Roberto, this function is very easy to implment, and is useful for > binding C/C++ libraries to lua, useful to use lua to manage the > dependency of userdatas, support a custom version of garbage collect, > and back-compatible with the Lua 5.2-beta, Can you merge it into the > Lua 5.2 trunk? or Is it has other issue? Hopes for your reply :) > > thank everybody in list, too :) > Attach a zip without binary :(
Attachment:
Lua-5.2.0-beta_with_ev.zip
Description: Zip archive