ltm.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. ** $Id: ltm.h,v 1.25 2001/06/06 18:00:19 roberto Exp roberto $
  3. ** Tag methods
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef ltm_h
  7. #define ltm_h
  8. #include "lobject.h"
  9. #include "lstate.h"
  10. /*
  11. * WARNING: if you change the order of this enumeration,
  12. * grep "ORDER TM"
  13. */
  14. typedef enum {
  15. TM_GETTABLE = 0,
  16. TM_SETTABLE,
  17. TM_INDEX,
  18. TM_GETGLOBAL,
  19. TM_SETGLOBAL,
  20. TM_ADD,
  21. TM_SUB,
  22. TM_MUL,
  23. TM_DIV,
  24. TM_POW,
  25. TM_UNM,
  26. TM_LT,
  27. TM_CONCAT,
  28. TM_GC,
  29. TM_FUNCTION,
  30. TM_N /* number of elements in the enum */
  31. } TMS;
  32. /*
  33. ** masks for allowable tag methods
  34. ** (see `luaT_validevents')
  35. */
  36. #define HAS_TM_GETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \
  37. (1<<LUA_TTABLE) | \
  38. (1<<LUA_TNIL)))
  39. #define HAS_TM_SETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \
  40. (1<<LUA_TTABLE) | \
  41. (1<<LUA_TNIL) | \
  42. (1<<LUA_TFUNCTION)))
  43. struct TM {
  44. Closure *method[TM_N];
  45. Udata *collected; /* list of garbage-collected udata with this tag */
  46. TString *name; /* type name */
  47. int basictype;
  48. };
  49. #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event])
  50. #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e)))
  51. #define typenamebytag(G, t) getstr(G->TMtable[t].name)
  52. #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag)
  53. extern const l_char *const luaT_eventname[];
  54. void luaT_init (lua_State *L);
  55. int luaT_newtag (lua_State *L, const l_char *name, int basictype);
  56. const l_char *luaT_typename (global_State *G, const TObject *o);
  57. int luaT_tag (const TObject *o);
  58. int luaT_validevent (int t, int e); /* used by compatibility module */
  59. #endif