18e3e3a7aSWarner Losh /* 2*0495ed39SKyle Evans ** $Id: lstring.h $ 38e3e3a7aSWarner Losh ** String table (keep all strings handled by Lua) 48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h 58e3e3a7aSWarner Losh */ 68e3e3a7aSWarner Losh 78e3e3a7aSWarner Losh #ifndef lstring_h 88e3e3a7aSWarner Losh #define lstring_h 98e3e3a7aSWarner Losh 108e3e3a7aSWarner Losh #include "lgc.h" 118e3e3a7aSWarner Losh #include "lobject.h" 128e3e3a7aSWarner Losh #include "lstate.h" 138e3e3a7aSWarner Losh 148e3e3a7aSWarner Losh 15*0495ed39SKyle Evans /* 16*0495ed39SKyle Evans ** Memory-allocation error message must be preallocated (it cannot 17*0495ed39SKyle Evans ** be created after memory is exhausted) 18*0495ed39SKyle Evans */ 19*0495ed39SKyle Evans #define MEMERRMSG "not enough memory" 208e3e3a7aSWarner Losh 21*0495ed39SKyle Evans 22*0495ed39SKyle Evans /* 23*0495ed39SKyle Evans ** Size of a TString: Size of the header plus space for the string 24*0495ed39SKyle Evans ** itself (including final '\0'). 25*0495ed39SKyle Evans */ 26*0495ed39SKyle Evans #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 278e3e3a7aSWarner Losh 288e3e3a7aSWarner Losh #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 298e3e3a7aSWarner Losh (sizeof(s)/sizeof(char))-1)) 308e3e3a7aSWarner Losh 318e3e3a7aSWarner Losh 328e3e3a7aSWarner Losh /* 338e3e3a7aSWarner Losh ** test whether a string is a reserved word 348e3e3a7aSWarner Losh */ 35*0495ed39SKyle Evans #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 368e3e3a7aSWarner Losh 378e3e3a7aSWarner Losh 388e3e3a7aSWarner Losh /* 398e3e3a7aSWarner Losh ** equality for short strings, which are always internalized 408e3e3a7aSWarner Losh */ 41*0495ed39SKyle Evans #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 428e3e3a7aSWarner Losh 438e3e3a7aSWarner Losh 448e3e3a7aSWarner Losh LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 458e3e3a7aSWarner Losh LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 468e3e3a7aSWarner Losh LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 478e3e3a7aSWarner Losh LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 488e3e3a7aSWarner Losh LUAI_FUNC void luaS_clearcache (global_State *g); 498e3e3a7aSWarner Losh LUAI_FUNC void luaS_init (lua_State *L); 508e3e3a7aSWarner Losh LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51*0495ed39SKyle Evans LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 528e3e3a7aSWarner Losh LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 538e3e3a7aSWarner Losh LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 548e3e3a7aSWarner Losh LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 558e3e3a7aSWarner Losh 568e3e3a7aSWarner Losh 578e3e3a7aSWarner Losh #endif 58