lrotable.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Read-only tables for Lua */
  2. #ifndef lrotable_h
  3. #define lrotable_h
  4. #include "lua.h"
  5. #include "llimits.h"
  6. #include "lobject.h"
  7. #include "luaconf.h"
  8. /* Macros one can use to define rotable entries */
  9. #ifndef LUA_PACK_VALUE
  10. #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
  11. #define LRO_LUDATA(v) {{.p = v}, LUA_TLIGHTUSERDATA}
  12. #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
  13. #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
  14. #define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
  15. #else // #ifndef LUA_PACK_VALUE
  16. #define LRO_NUMVAL(v) {.value.n = v}
  17. #ifdef ELUA_ENDIAN_LITTLE
  18. #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}}
  19. #define LRO_LUDATA(v) {{(int)v, add_sig(LUA_TLIGHTUSERDATA)}}
  20. #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}}
  21. #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}}
  22. #else // #ifdef ELUA_ENDIAN_LITTLE
  23. #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}}
  24. #define LRO_LUDATA(v) {{add_sig(LUA_TLIGHTUSERDATA), (int)v}}
  25. #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}}
  26. #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}}
  27. #endif // #ifdef ELUA_ENDIAN_LITTLE
  28. #endif // #ifndef LUA_PACK_VALUE
  29. #define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = k}}
  30. #define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}}
  31. #define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}}
  32. /* Maximum length of a rotable name and of a string key*/
  33. #define LUA_MAX_ROTABLE_NAME 32
  34. /* Type of a numeric key in a rotable */
  35. typedef int luaR_numkey;
  36. /* The next structure defines the type of a key */
  37. typedef struct
  38. {
  39. int type;
  40. union
  41. {
  42. const char* strkey;
  43. luaR_numkey numkey;
  44. } id;
  45. } luaR_key;
  46. /* An entry in the read only table */
  47. typedef struct
  48. {
  49. const luaR_key key;
  50. const TValue value;
  51. } luaR_entry;
  52. /* A rotable */
  53. typedef struct
  54. {
  55. const char *name;
  56. const luaR_entry *pentries;
  57. } luaR_table;
  58. void* luaR_findglobal(const char *key, unsigned len);
  59. int luaR_findfunction(lua_State *L, const luaR_entry *ptable);
  60. const TValue* luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos);
  61. void luaR_getcstr(char *dest, const TString *src, size_t maxsize);
  62. void luaR_next(lua_State *L, void *data, TValue *key, TValue *val);
  63. void* luaR_getmeta(void *data);
  64. #ifdef LUA_META_ROTABLES
  65. int luaR_isrotable(void *p);
  66. #else
  67. #define luaR_isrotable(p) (0)
  68. #endif
  69. #endif