[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature request : More lightuserdata types
- From: Flyer31 Test <flyer31@...>
- Date: Tue, 22 Feb 2022 13:50:15 +0100
Why don't you just use "normal c userdata", if you want metafunctions?
(I assume that in this case your userdata quite sure is anyway somehow
"more important" / more "heavy"?).
On Tue, Feb 22, 2022 at 6:13 AM 云风 Cloud Wu <cloudwu@gmail.com> wrote:
>
> 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