2 ** $Id: ltm.c,v 2.14 2011/06/02 19:31:40 roberto Exp $
4 ** See Copyright Notice in lua.h
22 static const char udatatypename
[] = "userdata";
24 LUAI_DDEF
const char *const luaT_typenames_
[LUA_TOTALTAGS
] = {
26 "nil", "boolean", udatatypename
, "number",
27 "string", "table", "function", udatatypename
, "thread",
28 "proto", "upval" /* these last two cases are used for tests only */
32 void luaT_init(lua_State
*L
) {
33 static const char *const luaT_eventname
[] = { /* ORDER TM */
34 "__index", "__newindex",
35 "__gc", "__mode", "__len", "__eq",
36 "__add", "__sub", "__mul", "__div", "__mod",
37 "__pow", "__unm", "__lt", "__le",
41 for (i
= 0; i
< TM_N
; i
++) {
42 G(L
)->tmname
[i
] = luaS_new(L
, luaT_eventname
[i
]);
43 luaS_fix(G(L
)->tmname
[i
]); /* never collect these names */
49 ** function to be used with macro "fasttm": optimized for absence of
52 const TValue
*luaT_gettm(Table
*events
, TMS event
, TString
*ename
) {
53 const TValue
*tm
= luaH_getstr(events
, ename
);
54 lua_assert(event
<= TM_EQ
);
55 if (ttisnil(tm
)) { /* no tag method? */
56 events
->flags
|= cast_byte(1u << event
); /* cache this fact */
62 const TValue
*luaT_gettmbyobj(lua_State
*L
, const TValue
*o
, TMS event
) {
66 mt
= hvalue(o
)->metatable
;
69 mt
= uvalue(o
)->metatable
;
72 mt
= G(L
)->mt
[ttypenv(o
)];
74 return (mt
? luaH_getstr(mt
, G(L
)->tmname
[event
]) : luaO_nilobject
);