Fix 32/64 bit portability issue with upval->v.
[luajit-2.0/celess22.git] / src / lj_str.h
blob5a4fcb9a9bc0902dba1c784e14822d66e8f7257c
1 /*
2 ** String handling.
3 ** Copyright (C) 2005-2010 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #ifndef _LJ_STR_H
7 #define _LJ_STR_H
9 #include <stdarg.h>
11 #include "lj_obj.h"
13 /* String interning. */
14 LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);
15 LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);
16 LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);
17 LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
19 #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
20 #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))
22 /* Type conversions. */
23 LJ_FUNC int LJ_FASTCALL lj_str_numconv(const char *s, TValue *n);
24 LJ_FUNC int LJ_FASTCALL lj_str_tonum(GCstr *str, TValue *n);
25 LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np);
26 LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k);
28 /* String formatting. */
29 LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp);
30 LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
31 #if defined(__GNUC__)
32 __attribute__ ((format (printf, 2, 3)))
33 #endif
36 /* Resizable string buffers. Struct definition in lj_obj.h. */
37 LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz);
39 #define lj_str_initbuf(L, sb) ((sb)->buf = NULL, (sb)->sz = 0)
40 #define lj_str_resetbuf(sb) ((sb)->n = 0)
41 #define lj_str_resizebuf(L, sb, size) \
42 ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \
43 (sb)->sz = (size))
44 #define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz)
46 #endif