lua-users home
lua-l archive

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


The reimplementation of metamethods for primitive types is really cool, but it still suffers from the problems which tag methods for primitive types had in previous versions of Lua: the change to behaviour is not localizable.

A quick glance at the code seems to indicate a possibility, though:

ltm.c:70
    default:
      mt = G(L)->mt[ttype(o)];

If this were changed so that the metatable were looked up in the function environment, the behaviour change could be localized to the function environment. All this would need would be a vector of primitive type metatable names (something like __nil, __string, __number, etc.)

Then this code could be changed to

    default:
mt = luaH_getstr(&clvalue(L->ci->func)->l->env, G(L)->tmtname[ttype(o)]);

or something of the sort, where tmtname is constructed similarly to tmname.

If luaH_getstr were available for in-lining in ltm.c, this would probably be reasonably competitive to the current code (which could easily be accomplished by combining ltm.c with ltable.c)

R.