1997-09-17 03:25:59 +08:00
|
|
|
/*
|
2001-12-06 04:15:18 +08:00
|
|
|
** $Id: ltm.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $
|
1997-09-17 03:25:59 +08:00
|
|
|
** Tag methods
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-06-12 21:52:05 +08:00
|
|
|
#include "lua.h"
|
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
#include "lobject.h"
|
1997-11-20 01:29:23 +08:00
|
|
|
#include "lstate.h"
|
2001-01-26 00:45:36 +08:00
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltable.h"
|
1997-09-17 03:25:59 +08:00
|
|
|
#include "ltm.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-12-06 04:15:18 +08:00
|
|
|
const char *const luaT_typenames[] = {
|
|
|
|
"userdata", "nil", "number", "string", "table", "function"
|
1997-09-17 03:25:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-11-22 21:12:07 +08:00
|
|
|
void luaT_init (lua_State *L) {
|
2001-12-06 04:15:18 +08:00
|
|
|
static const char *const luaT_eventname[] = { /* ORDER TM */
|
|
|
|
"gettable", "settable", "index",
|
|
|
|
"gc",
|
|
|
|
"add", "sub", "mul", "div",
|
|
|
|
"pow", "unm", "lt", "concat",
|
|
|
|
"call"
|
2001-01-26 00:45:36 +08:00
|
|
|
};
|
|
|
|
int i;
|
2001-12-06 04:15:18 +08:00
|
|
|
for (i=0; i<TM_N; i++) {
|
|
|
|
G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
|
|
|
|
G(L)->tmname[i]->tsv.marked = FIXMARK; /* never collect these names */
|
2001-01-26 00:45:36 +08:00
|
|
|
}
|
1997-09-17 03:25:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-06 04:15:18 +08:00
|
|
|
const TObject *luaT_gettm (Table *events, TMS event, TString *ename) {
|
|
|
|
const TObject *tm = luaH_getstr(events, ename);
|
|
|
|
if (ttype(tm) == LUA_TNIL) { /* no tag method? */
|
|
|
|
events->flags |= (1<<event); /* cache this fact */
|
|
|
|
return NULL;
|
1997-09-17 03:25:59 +08:00
|
|
|
}
|
2001-12-06 04:15:18 +08:00
|
|
|
else return tm;
|
1997-09-17 03:25:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-06 04:15:18 +08:00
|
|
|
const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event) {
|
|
|
|
switch (ttype(o)) {
|
2001-01-26 00:45:36 +08:00
|
|
|
case LUA_TTABLE:
|
2001-12-06 04:15:18 +08:00
|
|
|
return fasttm(L, hvalue(o)->eventtable, event);
|
|
|
|
case LUA_TUSERDATA:
|
|
|
|
return fasttm(L, uvalue(o)->uv.eventtable, event);
|
2000-10-05 21:00:17 +08:00
|
|
|
default:
|
2001-12-06 04:15:18 +08:00
|
|
|
return NULL;
|
2000-10-05 21:00:17 +08:00
|
|
|
}
|
1997-09-17 03:25:59 +08:00
|
|
|
}
|
|
|
|
|