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