lua-users home
lua-l archive

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


> On Aug 18, 2015, at 8:18 PM, 云风 Cloud Wu <cloudwu@gmail.com> wrote:
> 
> 
> So I suggest introduce a new mechanism of userdata to simplify them. I call it userdata slice (maybe it's not a good name).
> 
> If we can associate an integer to the userdata value, the userdata whould be more flexible. It is different from uservalue, because uservalue is in userdata object, not in value.
> 
> An userdata object has only one uservalue , but each userdata value can has an unique associated integer.
> 
> Two C API needed:
> 
> int lua_getuserslice(lua_State *L, int index);
> void lua_setuserslice(lua_State *L, int index, int slice);
> 

-1 on this. One of the advantages (for me) of userdata in Lua is that there is *no* language defined way that userdata can be modified. This means a C library can use Lua as the container for opaque data and be assured that whatever it stores there is not meddled with. If you want this sort of functionality on some specific userdata, then it’s pretty easy to expose an appropriate custom API for that purpose.

—Tim