2 ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
4 ** See Copyright Notice in lua.h
22 const char *const luaT_typenames[] = {
23 "nil", "boolean", "userdata", "number",
24 "string", "table", "function", "userdata", "thread",
29 void luaT_init (lua_State *L) {
30 static const char *const luaT_eventname[] = { /* ORDER TM */
31 "__index", "__newindex",
32 "__gc", "__mode", "__eq",
33 "__add", "__sub", "__mul", "__div", "__mod",
34 "__pow", "__unm", "__len", "__lt", "__le",
38 for (i=0; i<TM_N; i++) {
39 G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
40 luaS_fix(G(L)->tmname[i]); /* never collect these names */
46 ** function to be used with macro "fasttm": optimized for absence of
49 const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
50 const TValue *tm = luaH_getstr(events, ename);
51 lua_assert(event <= TM_EQ);
52 if (ttisnil(tm)) { /* no tag method? */
53 events->flags |= cast_byte(1u<<event); /* cache this fact */
60 const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
64 mt = hvalue(o)->metatable;
67 mt = uvalue(o)->metatable;
71 mt = G(L)->mt[LUA_TNUMBER];
75 mt = G(L)->mt[ttype(o)];
77 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);