ltm.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. ** $Id: ltm.h,v 1.28 2001/10/02 16:43:54 roberto Exp $
  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 char *const luaT_eventname[];
  54. void luaT_init (lua_State *L);
  55. int luaT_newtag (lua_State *L, const char *name, int basictype);
  56. const char *luaT_typename (global_State *G, const TObject *o);
  57. int luaT_tag (const TObject *o);
  58. #endif