2 ** $Id: ltm.c,v 2.14.1.1 2013/04/12 18:48:47 roberto Exp $
4 ** See Copyright Notice in lua.h
11 #include <sys/lua/lua.h>
20 static const char udatatypename
[] = "userdata";
22 LUAI_DDEF
const char *const luaT_typenames_
[LUA_TOTALTAGS
] = {
24 "nil", "boolean", udatatypename
, "number",
25 "string", "table", "function", udatatypename
, "thread",
26 "proto", "upval" /* these last two cases are used for tests only */
30 void luaT_init (lua_State
*L
) {
31 static const char *const luaT_eventname
[] = { /* ORDER TM */
32 "__index", "__newindex",
33 "__gc", "__mode", "__len", "__eq",
34 "__add", "__sub", "__mul", "__div", "__mod",
35 "__pow", "__unm", "__lt", "__le",
39 for (i
=0; i
<TM_N
; i
++) {
40 G(L
)->tmname
[i
] = luaS_new(L
, luaT_eventname
[i
]);
41 luaS_fix(G(L
)->tmname
[i
]); /* never collect these names */
47 ** function to be used with macro "fasttm": optimized for absence of
50 const TValue
*luaT_gettm (Table
*events
, TMS event
, TString
*ename
) {
51 const TValue
*tm
= luaH_getstr(events
, ename
);
52 lua_assert(event
<= TM_EQ
);
53 if (ttisnil(tm
)) { /* no tag method? */
54 events
->flags
|= cast_byte(1u<<event
); /* cache this fact */
61 const TValue
*luaT_gettmbyobj (lua_State
*L
, const TValue
*o
, TMS event
) {
65 mt
= hvalue(o
)->metatable
;
68 mt
= uvalue(o
)->metatable
;
71 mt
= G(L
)->mt
[ttypenv(o
)];
73 return (mt
? luaH_getstr(mt
, G(L
)->tmname
[event
]) : luaO_nilobject
);