aboutsummaryrefslogtreecommitdiff
path: root/libs/lua/src/ltm.c
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-16 10:58:21 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:52:45 (GMT)
commit3c1d7bb1c521e824dfa46903fd4014722d0f5a29 (patch)
treeb9d8ab1f95aa608cbef817550ccc4bd42534dcd6 /libs/lua/src/ltm.c
parent2223c879bf41d2b4f40fa43db478ba1bce8523de (diff)
downloadfluxbox_pavel-3c1d7bb1c521e824dfa46903fd4014722d0f5a29.zip
fluxbox_pavel-3c1d7bb1c521e824dfa46903fd4014722d0f5a29.tar.bz2
Add lua as an internal library in libs/lua
Diffstat (limited to 'libs/lua/src/ltm.c')
-rw-r--r--libs/lua/src/ltm.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/libs/lua/src/ltm.c b/libs/lua/src/ltm.c
new file mode 100644
index 0000000..c27f0f6
--- /dev/null
+++ b/libs/lua/src/ltm.c
@@ -0,0 +1,75 @@
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*/
6
7
8#include <string.h>
9
10#define ltm_c
11#define LUA_CORE
12
13#include "lua.h"
14
15#include "lobject.h"
16#include "lstate.h"
17#include "lstring.h"
18#include "ltable.h"
19#include "ltm.h"
20
21
22
23const char *const luaT_typenames[] = {
24 "nil", "boolean", "userdata", "number",
25 "string", "table", "function", "userdata", "thread",
26 "proto", "upval"
27};
28
29
30void luaT_init (lua_State *L) {
31 static const char *const luaT_eventname[] = { /* ORDER TM */
32 "__index", "__newindex",
33 "__gc", "__mode", "__eq",
34 "__add", "__sub", "__mul", "__div", "__mod",
35 "__pow", "__unm", "__len", "__lt", "__le",
36 "__concat", "__call"
37 };
38 int i;
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 */
42 }
43}
44
45
46/*
47** function to be used with macro "fasttm": optimized for absence of
48** tag methods
49*/
50const 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 */
55 return NULL;
56 }
57 else return tm;
58}
59
60
61const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
62 Table *mt;
63 switch (ttype(o)) {
64 case LUA_TTABLE:
65 mt = hvalue(o)->metatable;
66 break;
67 case LUA_TUSERDATA:
68 mt = uvalue(o)->metatable;
69 break;
70 default:
71 mt = G(L)->mt[ttype(o)];
72 }
73 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
74}
75