lstring.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** $Id: lstring.h $
  3. ** String table (keep all strings handled by Lua)
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lstring_h
  7. #define lstring_h
  8. #include "lgc.h"
  9. #include "lobject.h"
  10. #include "lstate.h"
  11. /*
  12. ** Memory-allocation error message must be preallocated (it cannot
  13. ** be created after memory is exhausted)
  14. */
  15. #define MEMERRMSG "not enough memory"
  16. /*
  17. ** Maximum length for short strings, that is, strings that are
  18. ** internalized. (Cannot be smaller than reserved words or tags for
  19. ** metamethods, as these strings must be internalized;
  20. ** #("function") = 8, #("__newindex") = 10.)
  21. */
  22. #if !defined(LUAI_MAXSHORTLEN)
  23. #define LUAI_MAXSHORTLEN 40
  24. #endif
  25. /*
  26. ** Size of a short TString: Size of the header plus space for the string
  27. ** itself (including final '\0').
  28. */
  29. #define sizestrshr(l) \
  30. (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
  31. #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
  32. (sizeof(s)/sizeof(char))-1))
  33. /*
  34. ** test whether a string is a reserved word
  35. */
  36. #define isreserved(s) (strisshr(s) && (s)->extra > 0)
  37. /*
  38. ** equality for short strings, which are always internalized
  39. */
  40. #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
  41. LUAI_FUNC unsigned luaS_hash (const char *str, size_t l, unsigned seed);
  42. LUAI_FUNC unsigned luaS_hashlongstr (TString *ts);
  43. LUAI_FUNC int luaS_eqstr (TString *a, TString *b);
  44. LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
  45. LUAI_FUNC void luaS_clearcache (global_State *g);
  46. LUAI_FUNC void luaS_init (lua_State *L);
  47. LUAI_FUNC void luaS_remove (lua_State *L, TString *ts);
  48. LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s,
  49. unsigned short nuvalue);
  50. LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
  51. LUAI_FUNC TString *luaS_new (lua_State *L, const char *str);
  52. LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);
  53. LUAI_FUNC TString *luaS_newextlstr (lua_State *L,
  54. const char *s, size_t len, lua_Alloc falloc, void *ud);
  55. LUAI_FUNC size_t luaS_sizelngstr (size_t len, int kind);
  56. LUAI_FUNC TString *luaS_normstr (lua_State *L, TString *ts);
  57. #endif