lua-users home
lua-l archive

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


> On 27 Jan 2017, at 01:16, nobody <nobody+lua-list@afra-berlin.de> wrote:
> 
> 
> *** lbaselib.c-orig	2017-01-27 00:33:07.854011135 +0100
> --- lbaselib.c-type2	2017-01-27 00:32:46.670792561 +0100
> *************** static int luaB_type (lua_State *L) {
> *** 202,207 ****
> --- 202,212 ----
>    int t = lua_type(L, 1);
>    luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
>    lua_pushstring(L, lua_typename(L, t));
> +   int tt = luaL_getmetafield(L, 1, "__name");
> +   if (tt == LUA_TSTRING)
> +     return 2;
> +   if (tt != LUA_TNIL)
> +     lua_settop(L, -2);
>    return 1;
>  }
> 

You’re always getting the `__name` field, shouldn't this only be done if the original type is one that allows for individual meta-tables? eg. not calling it on a `string`, but only on `table` and `userdata` types?

Thijs