lj_str.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ** String handling.
  3. ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_STR_H
  6. #define _LJ_STR_H
  7. #include <stdarg.h>
  8. #include "lj_obj.h"
  9. /* String interning. */
  10. LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);
  11. LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);
  12. LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);
  13. LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
  14. #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
  15. #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))
  16. /* Type conversions. */
  17. LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o);
  18. LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k);
  19. LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np);
  20. LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k);
  21. LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o);
  22. #define LJ_STR_INTBUF (1+10)
  23. #define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR
  24. /* String formatting. */
  25. LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp);
  26. LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
  27. #if defined(__GNUC__)
  28. __attribute__ ((format (printf, 2, 3)))
  29. #endif
  30. ;
  31. /* Resizable string buffers. Struct definition in lj_obj.h. */
  32. LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz);
  33. #define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0)
  34. #define lj_str_resetbuf(sb) ((sb)->n = 0)
  35. #define lj_str_resizebuf(L, sb, size) \
  36. ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \
  37. (sb)->sz = (size))
  38. #define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz)
  39. #endif