diff options
Diffstat (limited to 'vendor/lua-bz2/compat-5.3.h')
-rw-r--r-- | vendor/lua-bz2/compat-5.3.h | 424 |
1 files changed, 424 insertions, 0 deletions
diff --git a/vendor/lua-bz2/compat-5.3.h b/vendor/lua-bz2/compat-5.3.h new file mode 100644 index 00000000..b730a4b8 --- /dev/null +++ b/vendor/lua-bz2/compat-5.3.h | |||
@@ -0,0 +1,424 @@ | |||
1 | #ifndef COMPAT53_H_ | ||
2 | #define COMPAT53_H_ | ||
3 | |||
4 | #include <stddef.h> | ||
5 | #include <limits.h> | ||
6 | #include <string.h> | ||
7 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) | ||
8 | extern "C" { | ||
9 | #endif | ||
10 | #include <lua.h> | ||
11 | #include <lauxlib.h> | ||
12 | #include <lualib.h> | ||
13 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) | ||
14 | } | ||
15 | #endif | ||
16 | |||
17 | |||
18 | #undef COMPAT53_INCLUDE_SOURCE | ||
19 | #if defined(COMPAT53_PREFIX) | ||
20 | /* - change the symbol names of functions to avoid linker conflicts | ||
21 | * - compat-5.3.c needs to be compiled (and linked) separately | ||
22 | */ | ||
23 | # if !defined(COMPAT53_API) | ||
24 | # define COMPAT53_API extern | ||
25 | # endif | ||
26 | #else /* COMPAT53_PREFIX */ | ||
27 | /* - make all functions static and include the source. | ||
28 | * - compat-5.3.c doesn't need to be compiled (and linked) separately | ||
29 | */ | ||
30 | # define COMPAT53_PREFIX compat53 | ||
31 | # undef COMPAT53_API | ||
32 | # if defined(__GNUC__) || defined(__clang__) | ||
33 | # define COMPAT53_API __attribute__((__unused__)) static | ||
34 | # else | ||
35 | # define COMPAT53_API static | ||
36 | # endif | ||
37 | # define COMPAT53_INCLUDE_SOURCE | ||
38 | #endif /* COMPAT53_PREFIX */ | ||
39 | |||
40 | #define COMPAT53_CONCAT_HELPER(a, b) a##b | ||
41 | #define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b) | ||
42 | |||
43 | |||
44 | |||
45 | /* declarations for Lua 5.1 */ | ||
46 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 | ||
47 | |||
48 | /* XXX not implemented: | ||
49 | * lua_arith (new operators) | ||
50 | * lua_upvalueid | ||
51 | * lua_upvaluejoin | ||
52 | * lua_version | ||
53 | * lua_yieldk | ||
54 | */ | ||
55 | |||
56 | #ifndef LUA_OK | ||
57 | # define LUA_OK 0 | ||
58 | #endif | ||
59 | #ifndef LUA_OPADD | ||
60 | # define LUA_OPADD 0 | ||
61 | #endif | ||
62 | #ifndef LUA_OPSUB | ||
63 | # define LUA_OPSUB 1 | ||
64 | #endif | ||
65 | #ifndef LUA_OPMUL | ||
66 | # define LUA_OPMUL 2 | ||
67 | #endif | ||
68 | #ifndef LUA_OPDIV | ||
69 | # define LUA_OPDIV 3 | ||
70 | #endif | ||
71 | #ifndef LUA_OPMOD | ||
72 | # define LUA_OPMOD 4 | ||
73 | #endif | ||
74 | #ifndef LUA_OPPOW | ||
75 | # define LUA_OPPOW 5 | ||
76 | #endif | ||
77 | #ifndef LUA_OPUNM | ||
78 | # define LUA_OPUNM 6 | ||
79 | #endif | ||
80 | #ifndef LUA_OPEQ | ||
81 | # define LUA_OPEQ 0 | ||
82 | #endif | ||
83 | #ifndef LUA_OPLT | ||
84 | # define LUA_OPLT 1 | ||
85 | #endif | ||
86 | #ifndef LUA_OPLE | ||
87 | # define LUA_OPLE 2 | ||
88 | #endif | ||
89 | |||
90 | /* LuaJIT/Lua 5.1 does not have the updated | ||
91 | * error codes for thread status/function returns (but some patched versions do) | ||
92 | * define it only if it's not found | ||
93 | */ | ||
94 | #if !defined(LUA_ERRGCMM) | ||
95 | /* Use + 2 because in some versions of Lua (Lua 5.1) | ||
96 | * LUA_ERRFILE is defined as (LUA_ERRERR+1) | ||
97 | * so we need to avoid it (LuaJIT might have something at this | ||
98 | * integer value too) | ||
99 | */ | ||
100 | # define LUA_ERRGCMM (LUA_ERRERR + 2) | ||
101 | #endif /* LUA_ERRGCMM define */ | ||
102 | |||
103 | typedef size_t lua_Unsigned; | ||
104 | |||
105 | typedef struct luaL_Buffer_53 { | ||
106 | luaL_Buffer b; /* make incorrect code crash! */ | ||
107 | char *ptr; | ||
108 | size_t nelems; | ||
109 | size_t capacity; | ||
110 | lua_State *L2; | ||
111 | } luaL_Buffer_53; | ||
112 | #define luaL_Buffer luaL_Buffer_53 | ||
113 | |||
114 | /* In PUC-Rio 5.1, userdata is a simple FILE* | ||
115 | * In LuaJIT, it's a struct where the first member is a FILE* | ||
116 | * We can't support the `closef` member | ||
117 | */ | ||
118 | typedef struct luaL_Stream { | ||
119 | FILE *f; | ||
120 | } luaL_Stream; | ||
121 | |||
122 | #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) | ||
123 | COMPAT53_API int lua_absindex (lua_State *L, int i); | ||
124 | |||
125 | #define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith) | ||
126 | COMPAT53_API void lua_arith (lua_State *L, int op); | ||
127 | |||
128 | #define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare) | ||
129 | COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op); | ||
130 | |||
131 | #define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy) | ||
132 | COMPAT53_API void lua_copy (lua_State *L, int from, int to); | ||
133 | |||
134 | #define lua_getuservalue(L, i) \ | ||
135 | (lua_getfenv((L), (i)), lua_type((L), -1)) | ||
136 | #define lua_setuservalue(L, i) \ | ||
137 | (luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i))) | ||
138 | |||
139 | #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) | ||
140 | COMPAT53_API void lua_len (lua_State *L, int i); | ||
141 | |||
142 | #define lua_pushstring(L, s) \ | ||
143 | (lua_pushstring((L), (s)), lua_tostring((L), -1)) | ||
144 | |||
145 | #define lua_pushlstring(L, s, len) \ | ||
146 | ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) | ||
147 | |||
148 | #ifndef luaL_newlibtable | ||
149 | # define luaL_newlibtable(L, l) \ | ||
150 | (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) | ||
151 | #endif | ||
152 | #ifndef luaL_newlib | ||
153 | # define luaL_newlib(L, l) \ | ||
154 | (luaL_newlibtable((L), (l)), luaL_register((L), NULL, (l))) | ||
155 | #endif | ||
156 | |||
157 | #define lua_pushglobaltable(L) \ | ||
158 | lua_pushvalue((L), LUA_GLOBALSINDEX) | ||
159 | |||
160 | #define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp) | ||
161 | COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p); | ||
162 | |||
163 | #define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp) | ||
164 | COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); | ||
165 | |||
166 | #define lua_rawlen(L, i) lua_objlen((L), (i)) | ||
167 | |||
168 | #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) | ||
169 | |||
170 | #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) | ||
171 | COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); | ||
172 | |||
173 | #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) | ||
174 | COMPAT53_API void luaL_checkversion (lua_State *L); | ||
175 | |||
176 | #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) | ||
177 | COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode); | ||
178 | |||
179 | #define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex) | ||
180 | COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode); | ||
181 | |||
182 | #define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx) | ||
183 | COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); | ||
184 | |||
185 | #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) | ||
186 | COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); | ||
187 | |||
188 | #define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable) | ||
189 | COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); | ||
190 | |||
191 | #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) | ||
192 | COMPAT53_API lua_Integer luaL_len (lua_State *L, int i); | ||
193 | |||
194 | #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) | ||
195 | COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); | ||
196 | |||
197 | #define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable) | ||
198 | COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname); | ||
199 | |||
200 | #define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata) | ||
201 | COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname); | ||
202 | |||
203 | #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) | ||
204 | COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); | ||
205 | |||
206 | #define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult) | ||
207 | COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname); | ||
208 | |||
209 | #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) | ||
210 | COMPAT53_API int luaL_execresult (lua_State *L, int stat); | ||
211 | |||
212 | #define lua_callk(L, na, nr, ctx, cont) \ | ||
213 | ((void)(ctx), (void)(cont), lua_call((L), (na), (nr))) | ||
214 | #define lua_pcallk(L, na, nr, err, ctx, cont) \ | ||
215 | ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err))) | ||
216 | |||
217 | #define lua_resume(L, from, nargs) \ | ||
218 | ((void)(from), lua_resume((L), (nargs))) | ||
219 | |||
220 | #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53) | ||
221 | COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B); | ||
222 | |||
223 | #define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53) | ||
224 | COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s); | ||
225 | |||
226 | #define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53) | ||
227 | COMPAT53_API void luaL_addlstring (luaL_Buffer_53 *B, const char *s, size_t l); | ||
228 | |||
229 | #define luaL_addvalue COMPAT53_CONCAT(COMPAT53_PREFIX, _addvalue_53) | ||
230 | COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B); | ||
231 | |||
232 | #define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53) | ||
233 | COMPAT53_API void luaL_pushresult (luaL_Buffer_53 *B); | ||
234 | |||
235 | #undef luaL_buffinitsize | ||
236 | #define luaL_buffinitsize(L, B, s) \ | ||
237 | (luaL_buffinit((L), (B)), luaL_prepbuffsize((B), (s))) | ||
238 | |||
239 | #undef luaL_prepbuffer | ||
240 | #define luaL_prepbuffer(B) \ | ||
241 | luaL_prepbuffsize((B), LUAL_BUFFERSIZE) | ||
242 | |||
243 | #undef luaL_addchar | ||
244 | #define luaL_addchar(B, c) \ | ||
245 | ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize((B), 1)), \ | ||
246 | ((B)->ptr[(B)->nelems++] = (c))) | ||
247 | |||
248 | #undef luaL_addsize | ||
249 | #define luaL_addsize(B, s) \ | ||
250 | ((B)->nelems += (s)) | ||
251 | |||
252 | #undef luaL_addstring | ||
253 | #define luaL_addstring(B, s) \ | ||
254 | luaL_addlstring((B), (s), strlen((s))) | ||
255 | |||
256 | #undef luaL_pushresultsize | ||
257 | #define luaL_pushresultsize(B, s) \ | ||
258 | (luaL_addsize((B), (s)), luaL_pushresult((B))) | ||
259 | |||
260 | #if defined(LUA_COMPAT_APIINTCASTS) | ||
261 | #define lua_pushunsigned(L, n) \ | ||
262 | lua_pushinteger((L), (lua_Integer)(n)) | ||
263 | #define lua_tounsignedx(L, i, is) \ | ||
264 | ((lua_Unsigned)lua_tointegerx((L), (i), (is))) | ||
265 | #define lua_tounsigned(L, i) \ | ||
266 | lua_tounsignedx((L), (i), NULL) | ||
267 | #define luaL_checkunsigned(L, a) \ | ||
268 | ((lua_Unsigned)luaL_checkinteger((L), (a))) | ||
269 | #define luaL_optunsigned(L, a, d) \ | ||
270 | ((lua_Unsigned)luaL_optinteger((L), (a), (lua_Integer)(d))) | ||
271 | #endif | ||
272 | |||
273 | #endif /* Lua 5.1 only */ | ||
274 | |||
275 | |||
276 | |||
277 | /* declarations for Lua 5.1 and 5.2 */ | ||
278 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502 | ||
279 | |||
280 | typedef int lua_KContext; | ||
281 | |||
282 | typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); | ||
283 | |||
284 | #define lua_dump(L, w, d, s) \ | ||
285 | ((void)(s), lua_dump((L), (w), (d))) | ||
286 | |||
287 | #define lua_getfield(L, i, k) \ | ||
288 | (lua_getfield((L), (i), (k)), lua_type((L), -1)) | ||
289 | |||
290 | #define lua_gettable(L, i) \ | ||
291 | (lua_gettable((L), (i)), lua_type((L), -1)) | ||
292 | |||
293 | #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) | ||
294 | COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); | ||
295 | |||
296 | #define lua_getextraspace COMPAT53_CONCAT(COMPAT53_PREFIX, _getextraspace) | ||
297 | COMPAT53_API void *lua_getextraspace (lua_State *L); | ||
298 | |||
299 | #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) | ||
300 | COMPAT53_API int lua_isinteger (lua_State *L, int index); | ||
301 | |||
302 | #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53) | ||
303 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); | ||
304 | |||
305 | #define lua_numbertointeger(n, p) \ | ||
306 | ((*(p) = (lua_Integer)(n)), 1) | ||
307 | |||
308 | #define lua_rawget(L, i) \ | ||
309 | (lua_rawget((L), (i)), lua_type((L), -1)) | ||
310 | |||
311 | #define lua_rawgeti(L, i, n) \ | ||
312 | (lua_rawgeti((L), (i), (n)), lua_type((L), -1)) | ||
313 | |||
314 | #define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate) | ||
315 | COMPAT53_API void lua_rotate (lua_State *L, int idx, int n); | ||
316 | |||
317 | #define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti) | ||
318 | COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i); | ||
319 | |||
320 | #define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber) | ||
321 | COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s); | ||
322 | |||
323 | #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) | ||
324 | COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); | ||
325 | |||
326 | #define luaL_getmetafield(L, o, e) \ | ||
327 | (luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL) | ||
328 | |||
329 | #define luaL_newmetatable(L, tn) \ | ||
330 | (luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0) | ||
331 | |||
332 | #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53) | ||
333 | COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, | ||
334 | lua_CFunction openf, int glb ); | ||
335 | |||
336 | #endif /* Lua 5.1 and Lua 5.2 */ | ||
337 | |||
338 | |||
339 | |||
340 | /* declarations for Lua 5.2 */ | ||
341 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 502 | ||
342 | |||
343 | /* XXX not implemented: | ||
344 | * lua_isyieldable | ||
345 | * lua_arith (new operators) | ||
346 | * lua_pushfstring (new formats) | ||
347 | */ | ||
348 | |||
349 | #define lua_getglobal(L, n) \ | ||
350 | (lua_getglobal((L), (n)), lua_type((L), -1)) | ||
351 | |||
352 | #define lua_getuservalue(L, i) \ | ||
353 | (lua_getuservalue((L), (i)), lua_type((L), -1)) | ||
354 | |||
355 | #define lua_pushlstring(L, s, len) \ | ||
356 | (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) | ||
357 | |||
358 | #define lua_rawgetp(L, i, p) \ | ||
359 | (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) | ||
360 | |||
361 | #define LUA_KFUNCTION(_name) \ | ||
362 | static int (_name)(lua_State *L, int status, lua_KContext ctx); \ | ||
363 | static int (_name ## _52)(lua_State *L) { \ | ||
364 | lua_KContext ctx; \ | ||
365 | int status = lua_getctx(L, &ctx); \ | ||
366 | return (_name)(L, status, ctx); \ | ||
367 | } \ | ||
368 | static int (_name)(lua_State *L, int status, lua_KContext ctx) | ||
369 | |||
370 | #define lua_pcallk(L, na, nr, err, ctx, cont) \ | ||
371 | lua_pcallk((L), (na), (nr), (err), (ctx), cont ## _52) | ||
372 | |||
373 | #define lua_callk(L, na, nr, ctx, cont) \ | ||
374 | lua_callk((L), (na), (nr), (ctx), cont ## _52) | ||
375 | |||
376 | #define lua_yieldk(L, nr, ctx, cont) \ | ||
377 | lua_yieldk((L), (nr), (ctx), cont ## _52) | ||
378 | |||
379 | #ifdef lua_call | ||
380 | # undef lua_call | ||
381 | # define lua_call(L, na, nr) \ | ||
382 | (lua_callk)((L), (na), (nr), 0, NULL) | ||
383 | #endif | ||
384 | |||
385 | #ifdef lua_pcall | ||
386 | # undef lua_pcall | ||
387 | # define lua_pcall(L, na, nr, err) \ | ||
388 | (lua_pcallk)((L), (na), (nr), (err), 0, NULL) | ||
389 | #endif | ||
390 | |||
391 | #ifdef lua_yield | ||
392 | # undef lua_yield | ||
393 | # define lua_yield(L, nr) \ | ||
394 | (lua_yieldk)((L), (nr), 0, NULL) | ||
395 | #endif | ||
396 | |||
397 | #endif /* Lua 5.2 only */ | ||
398 | |||
399 | |||
400 | |||
401 | /* other Lua versions */ | ||
402 | #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 504 | ||
403 | |||
404 | # error "unsupported Lua version (i.e. not Lua 5.1, 5.2, 5.3, or 5.4)" | ||
405 | |||
406 | #endif /* other Lua versions except 5.1, 5.2, 5.3, and 5.4 */ | ||
407 | |||
408 | |||
409 | |||
410 | /* helper macro for defining continuation functions (for every version | ||
411 | * *except* Lua 5.2) */ | ||
412 | #ifndef LUA_KFUNCTION | ||
413 | #define LUA_KFUNCTION(_name) \ | ||
414 | static int (_name)(lua_State *L, int status, lua_KContext ctx) | ||
415 | #endif | ||
416 | |||
417 | |||
418 | #if defined(COMPAT53_INCLUDE_SOURCE) | ||
419 | # include "compat-5.3.c" | ||
420 | #endif | ||
421 | |||
422 | |||
423 | #endif /* COMPAT53_H_ */ | ||
424 | |||