Port to new grub_pci_iterate signature as of 2013-01-13, removing nested functions.
[grub-extras.git] / ltm.c
blob9ff53c79cd9c73fd58afb9672a6f86052ed2dace
1 /*
2 ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
3 ** Tag methods
4 ** See Copyright Notice in lua.h
5 */
7 #if 0
8 #include <string.h>
9 #endif
11 #define ltm_c
12 #define LUA_CORE
14 #include "lua.h"
16 #include "lobject.h"
17 #include "lstate.h"
18 #include "lstring.h"
19 #include "ltable.h"
20 #include "ltm.h"
24 const char *const luaT_typenames[] = {
25 "nil", "boolean", "userdata", "number",
26 "string", "table", "function", "userdata", "thread",
27 "proto", "upval"
31 void luaT_init (lua_State *L) {
32 static const char *const luaT_eventname[] = { /* ORDER TM */
33 "__index", "__newindex",
34 "__gc", "__mode", "__eq",
35 "__add", "__sub", "__mul", "__div", "__mod",
36 "__pow", "__unm", "__len", "__lt", "__le",
37 "__concat", "__call"
39 int i;
40 for (i=0; i<TM_N; i++) {
41 G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
42 luaS_fix(G(L)->tmname[i]); /* never collect these names */
48 ** function to be used with macro "fasttm": optimized for absence of
49 ** tag methods
51 const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
52 const TValue *tm = luaH_getstr(events, ename);
53 lua_assert(event <= TM_EQ);
54 if (ttisnil(tm)) { /* no tag method? */
55 events->flags |= cast_byte(1u<<event); /* cache this fact */
56 return NULL;
58 else return tm;
62 const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
63 Table *mt;
64 switch (ttype(o)) {
65 case LUA_TTABLE:
66 mt = hvalue(o)->metatable;
67 break;
68 case LUA_TUSERDATA:
69 mt = uvalue(o)->metatable;
70 break;
71 default:
72 mt = G(L)->mt[ttype(o)];
74 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);