lrotable.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
  12. #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
  13. #define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
  14. #else // #ifndef LUA_PACK_VALUE
  15. #define LRO_NUMVAL(v) {.value.n = v}
  16. #ifdef ELUA_ENDIAN_LITTLE
  17. #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}}
  18. #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}}
  19. #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}}
  20. #else // #ifdef ELUA_ENDIAN_LITTLE
  21. #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}}
  22. #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}}
  23. #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}}
  24. #endif // #ifdef ELUA_ENDIAN_LITTLE
  25. #endif // #ifndef LUA_PACK_VALUE
  26. #define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = k}}
  27. #define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}}
  28. #define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}}
  29. /* Maximum length of a rotable name and of a string key*/
  30. #define LUA_MAX_ROTABLE_NAME 32
  31. /* Type of a numeric key in a rotable */
  32. typedef int luaR_numkey;
  33. /* The next structure defines the type of a key */
  34. typedef struct
  35. {
  36. int type;
  37. union
  38. {
  39. const char* strkey;
  40. luaR_numkey numkey;
  41. } id;
  42. } luaR_key;
  43. /* An entry in the read only table */
  44. typedef struct
  45. {
  46. const luaR_key key;
  47. const TValue value;
  48. } luaR_entry;
  49. /* A rotable */
  50. typedef struct
  51. {
  52. const char *name;
  53. const luaR_entry *pentries;
  54. } luaR_table;
  55. void* luaR_findglobal(const char *key, unsigned len);
  56. int luaR_findfunction(lua_State *L, const luaR_entry *ptable);
  57. const TValue* luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos);
  58. void luaR_getcstr(char *dest, const TString *src, size_t maxsize);
  59. void luaR_next(lua_State *L, void *data, TValue *key, TValue *val);
  60. void* luaR_getmeta(void *data);
  61. #ifdef LUA_META_ROTABLES
  62. int luaR_isrotable(void *p);
  63. #else
  64. #define luaR_isrotable(p) (0)
  65. #endif
  66. #endif