[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Feature request : More lightuserdata types
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Tue, 22 Feb 2022 13:13:11 +0800
Lightuserdata is a value and all the lightuserdata share the same one metatable.
I think more lightuserdata type with independent metatable would be
helpful. I suggest changing some C APIs like these :
// Push a C pointer with type, returns a unique typeid (Not zero)
associated with this type.
int lua_pushlightuserdata(lua_State *L, void *p, const char *typename);
// Returns typeid if the value at the given index is a light userdata,
and 0 otherwise.
int lua_islightuserdata(lua_State *L, int index);
If we call lua_setmetatable with a lightuserdata, the metatable of
different types are independent.
The total numbers of types don't need to much, 64K (even 256) would
be a reasonable number, and it can be easily encoded in TValue struct.
--
http://blog.codingnow.com