rlm@1: /* rlm@1: ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ rlm@1: ** Tag methods rlm@1: ** See Copyright Notice in lua.h rlm@1: */ rlm@1: rlm@1: rlm@1: #include rlm@1: rlm@1: #define ltm_c rlm@1: #define LUA_CORE rlm@1: rlm@1: #include "lua.h" rlm@1: rlm@1: #include "lobject.h" rlm@1: #include "lstate.h" rlm@1: #include "lstring.h" rlm@1: #include "ltable.h" rlm@1: #include "ltm.h" rlm@1: rlm@1: rlm@1: rlm@1: const char *const luaT_typenames[] = { rlm@1: "nil", "boolean", "userdata", "number", rlm@1: "string", "table", "function", "userdata", "thread", rlm@1: "proto", "upval" rlm@1: }; rlm@1: rlm@1: rlm@1: void luaT_init (lua_State *L) { rlm@1: static const char *const luaT_eventname[] = { /* ORDER TM */ rlm@1: "__index", "__newindex", rlm@1: "__gc", "__mode", "__eq", rlm@1: "__add", "__sub", "__mul", "__div", "__mod", rlm@1: "__pow", "__unm", "__len", "__lt", "__le", rlm@1: "__concat", "__call" rlm@1: }; rlm@1: int i; rlm@1: for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); rlm@1: luaS_fix(G(L)->tmname[i]); /* never collect these names */ rlm@1: } rlm@1: } rlm@1: rlm@1: rlm@1: /* rlm@1: ** function to be used with macro "fasttm": optimized for absence of rlm@1: ** tag methods rlm@1: */ rlm@1: const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { rlm@1: const TValue *tm = luaH_getstr(events, ename); rlm@1: lua_assert(event <= TM_EQ); rlm@1: if (ttisnil(tm)) { /* no tag method? */ rlm@1: events->flags |= cast_byte(1u<metatable; rlm@1: break; rlm@1: case LUA_TUSERDATA: rlm@1: mt = uvalue(o)->metatable; rlm@1: break; rlm@1: default: rlm@1: mt = G(L)->mt[ttype(o)]; rlm@1: } rlm@1: return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); rlm@1: } rlm@1: