aboutsummaryrefslogtreecommitdiff
path: root/lprefix.h
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-01-21 14:37:41 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2015-01-21 14:37:41 +0100
commiteec3f9e44bee334542348bdd1d428417e22ed5e5 (patch)
tree82fe996fb72ee5a86b9f872fcf57df8fb888a280 /lprefix.h
parentc57750c925553f627701f2c4897ee6bd6488c7c1 (diff)
downloadlua-compat-5.3-eec3f9e44bee334542348bdd1d428417e22ed5e5.tar.gz
lua-compat-5.3-eec3f9e44bee334542348bdd1d428417e22ed5e5.tar.bz2
lua-compat-5.3-eec3f9e44bee334542348bdd1d428417e22ed5e5.zip
use Lua 5.3's source for string packing
Diffstat (limited to 'lprefix.h')
-rw-r--r--lprefix.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/lprefix.h b/lprefix.h
index 79f0bd8..2ee5802 100644
--- a/lprefix.h
+++ b/lprefix.h
@@ -54,6 +54,9 @@
54 54
55#ifdef ltablib_c 55#ifdef ltablib_c
56# define luaopen_table luaopen_compat53_table 56# define luaopen_table luaopen_compat53_table
57/* lua_rawgeti in compat53.h is implemented as a macro, so the
58 * function signature doesn't match when you use a function pointer
59 */
57static int compat53_rawgeti (lua_State *L, int i, lua_Integer n) { 60static int compat53_rawgeti (lua_State *L, int i, lua_Integer n) {
58 return lua_rawgeti(L, i, n); 61 return lua_rawgeti(L, i, n);
59} 62}
@@ -64,11 +67,50 @@ static void compat53_rawseti (lua_State *L, int i, lua_Integer n) {
64} 67}
65# undef lua_rawseti 68# undef lua_rawseti
66# define lua_rawseti compat53_rawseti 69# define lua_rawseti compat53_rawseti
70/* we have lua_compare emulation for Lua 5.1, but it involves calling
71 * Lua code, and the only use in the table library is for '<', so ...
72 */
67# if LUA_VERSION_NUM == 501 73# if LUA_VERSION_NUM == 501
68# undef lua_compare 74# undef lua_compare
69# define lua_compare(L, a, b, op) lua_lessthan(L, a, b) 75# define lua_compare(L, a, b, op) lua_lessthan(L, a, b)
70# endif 76# endif
71#endif /* ltablib_c */ 77#endif /* ltablib_c */
72 78
79#ifdef lstrlib_c
80/* move the string library open function out of the way (we only take
81 * the string packing functions)!
82 */
83# define luaopen_string luaopen_string_XXX
84/* used in string.format implementation, which we don't use: */
85# ifndef LUA_INTEGER_FRMLEN
86# define LUA_INTEGER_FRMLEN ""
87# define LUA_NUMBER_FRMLEN ""
88# endif
89# if LUA_VERSION_NUM < 503
90/* lstrlib assumes that lua_Integer and lua_Unsigned have the same
91 * size, so we use the unsigned equivalent of ptrdiff_t! */
92# define lua_Unsigned size_t
93# endif
94static int str_pack (lua_State *L);
95static int str_packsize (lua_State *L);
96static int str_unpack (lua_State *L);
97LUAMOD_API int luaopen_compat53_string (lua_State *L) {
98 luaL_Reg const funcs[] = {
99 { "pack", str_pack },
100 { "packsize", str_packsize },
101 { "unpack", str_unpack },
102 { NULL, NULL }
103 };
104 luaL_newlib(L, funcs);
105 return 1;
106}
107/* make luaopen_string(_XXX) static, so it (and all other referenced
108 * string functions) won't be included in the resulting dll
109 * (hopefully).
110 */
111# undef LUAMOD_API
112# define LUAMOD_API static
113#endif /* lstrlib.c */
114
73#endif 115#endif
74 116