summaryrefslogtreecommitdiff
path: root/vendor/compat53/c-api/compat-5.3.h
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-08-30 13:55:59 +1000
committerdaurnimator <quae@daurnimator.com>2017-08-30 13:56:07 +1000
commitb8e3766294b6bf11d70a8a202e633b2569675e77 (patch)
treec1f29081daf4a1dc3965ee260d88e2aeae9aa902 /vendor/compat53/c-api/compat-5.3.h
parentb92fca3b68e551d2583754c80196d524890e5ee4 (diff)
parent7333333568b13db56136e2354c55556adc7714ed (diff)
downloadluaossl-b8e3766294b6bf11d70a8a202e633b2569675e77.tar.gz
luaossl-b8e3766294b6bf11d70a8a202e633b2569675e77.tar.bz2
luaossl-b8e3766294b6bf11d70a8a202e633b2569675e77.zip
Merge commit '7333333568b13db56136e2354c55556adc7714ed' as 'vendor/compat53'
Diffstat (limited to 'vendor/compat53/c-api/compat-5.3.h')
-rw-r--r--vendor/compat53/c-api/compat-5.3.h388
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)
8extern "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
91typedef size_t lua_Unsigned;
92
93typedef 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)
103COMPAT53_API int lua_absindex (lua_State *L, int i);
104
105#define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith)
106COMPAT53_API void lua_arith (lua_State *L, int op);
107
108#define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare)
109COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op);
110
111#define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy)
112COMPAT53_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)
120COMPAT53_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)
141COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p);
142
143#define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp)
144COMPAT53_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)
149COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum);
150
151#define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx)
152COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum);
153
154#define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion)
155COMPAT53_API void luaL_checkversion (lua_State *L);
156
157#define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53)
158COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg);
159
160#define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable)
161COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name);
162
163#define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len)
164COMPAT53_API lua_Integer luaL_len (lua_State *L, int i);
165
166#define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs)
167COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
168
169#define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable)
170COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname);
171
172#define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata)
173COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname);
174
175#define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback)
176COMPAT53_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)
179COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname);
180
181#define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult)
182COMPAT53_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)
190COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B);
191
192#define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53)
193COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s);
194
195#define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53)
196COMPAT53_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)
199COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B);
200
201#define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53)
202COMPAT53_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
249typedef int lua_KContext;
250
251typedef 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)
263COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i);
264
265#define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger)
266COMPAT53_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)
278COMPAT53_API void lua_rotate (lua_State *L, int idx, int n);
279
280#define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti)
281COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i);
282
283#define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber)
284COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s);
285
286#define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring)
287COMPAT53_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)
296COMPAT53_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