lua/ltm.h

81 lines
1.7 KiB
C
Raw Normal View History

1997-09-16 23:25:59 +04:00
/*
2001-01-25 19:45:36 +03:00
** $Id: ltm.h,v 1.21 2001/01/24 16:20:54 roberto Exp roberto $
1997-09-16 23:25:59 +04:00
** Tag methods
** See Copyright Notice in lua.h
*/
#ifndef ltm_h
#define ltm_h
#include "lobject.h"
#include "lstate.h"
1997-09-16 23:25:59 +04:00
/*
* WARNING: if you change the order of this enumeration,
* grep "ORDER TM"
1997-09-16 23:25:59 +04:00
*/
typedef enum {
TM_GETTABLE = 0,
TM_SETTABLE,
TM_INDEX,
TM_GETGLOBAL,
TM_SETGLOBAL,
TM_ADD,
TM_SUB,
TM_MUL,
TM_DIV,
TM_POW,
TM_UNM,
TM_LT,
TM_CONCAT,
TM_GC,
TM_FUNCTION,
TM_N /* number of elements in the enum */
} TMS;
2001-01-24 19:20:54 +03:00
/*
** masks for allowable tag methods
2001-01-25 19:45:36 +03:00
** (see `luaT_validevents')
2001-01-24 19:20:54 +03:00
*/
#define HAS_TM_GETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \
(1<<LUA_TTABLE) | \
(1<<LUA_TNIL)))
#define HAS_TM_SETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \
(1<<LUA_TTABLE) | \
(1<<LUA_TNIL) | \
(1<<LUA_TFUNCTION)))
struct TM {
Closure *method[TM_N];
TString *collected; /* list of garbage-collected udata with this tag */
2001-01-25 19:45:36 +03:00
TString *name; /* type name */
int basictype;
};
1997-09-16 23:25:59 +04:00
#define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event])
#define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e)))
2000-10-05 16:14:08 +04:00
2001-01-25 19:45:36 +03:00
#define basictypename(G, t) (G->TMtable[t].name->str)
2000-10-05 16:14:08 +04:00
#define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag)
1997-09-16 23:25:59 +04:00
1999-08-17 00:52:00 +04:00
extern const char *const luaT_eventname[];
1997-09-16 23:25:59 +04:00
void luaT_init (lua_State *L);
2001-01-25 19:45:36 +03:00
int luaT_newtag (lua_State *L, const char *name, int basictype);
const char *luaT_typename (global_State *G, const TObject *o);
2000-10-05 16:14:08 +04:00
int luaT_tag (const TObject *o);
int luaT_validevent (int t, int e); /* used by compatibility module */
1997-09-16 23:25:59 +04:00
#endif