-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlextlib.h
95 lines (65 loc) · 3.38 KB
/
lextlib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef LEXTLIB_H
#define LEXTLIB_H
#include <stdio.h>
#include <stdbool.h>
#include <lua.h>
#include "lextlib_global.h"
#include "lextlib_lua52.h"
#define LUAX_FUNCTION(prefix, function) { #function, prefix##function }
/* [-0,+0,e] */
#define luaX_setconst(L, idx, prefix, val) \
(lua_pushinteger((L), (prefix##val)), lua_setfield((L), (idx) > 0 ? (idx) : (idx)-1, #val))
#define luaX_opt(L, func, narg, argname, def) \
(lua_isnoneornil((L), (narg)) ? (def) : func((L), (narg), (argname)))
#define luaX_stkdbg(L) { \
int i, top = lua_gettop(L); \
fprintf(stderr, "L%d -> %d items\n", __LINE__, top); \
for (i = top; i > 0; i--) { \
printf(" [%d] %s = %s\n", i, lua_typename(L, lua_type(L, i)), (lua_isstring(L, i) ? lua_tostring(L, i) : "?")); \
} \
}
#define luaX_passerr(L, func) { \
int ret = (func)(L); \
if (lua_isnil((L), -ret)) { \
return ret; \
} \
else { \
lua_pop((L), ret); \
} \
}
#define LUAX_STR_TYPENAME "luax_typename"
#define LUAX_STR_CLASS "luax_class"
extern const char* luaX_status2str (int status);
extern bool luaX_havetraceback (lua_State *L);
extern int luaX_settraceback (lua_State *L);
extern int luaX_traceback (lua_State *L);
extern int luaX_panic (lua_State *L);
extern void luaX_showstack (lua_State *L);
extern void luaX_error (lua_State *L, const char *fmt, ...) LUAX_DECL_NORETURN;
extern void luaX_preload (lua_State *L, const char *name, lua_CFunction function);
extern void luaX_restrict (lua_State *L);
extern const char* luaX_typename(lua_State *L, int narg);
extern const char* luaX_pushargerror (lua_State *L, int narg, const char *argname, const char *extramsg);
extern const char* luaX_pushtypeerror (lua_State *L, int narg, const char *argname, const char *tname);
extern void luaX_checktype (lua_State *L, int narg, const char *argname, int t);
extern int luaX_argerror (lua_State *L, int narg, const char *argname, const char *extramsg);
extern int luaX_typeerror (lua_State *L, int narg, const char *argname, const char *tname);
extern lua_Number luaX_checknumber (lua_State *L, int narg, const char *argname);
extern lua_Number luaX_optnumber (lua_State *L, int narg, const char *argname, lua_Number def);
extern lua_Integer luaX_checkinteger (lua_State *L, int narg, const char *argname);
extern lua_Integer luaX_optinteger (lua_State *L, int narg, const char *argname, lua_Integer def);
extern const char* luaX_checklstring (lua_State *L, int narg, const char *argname, size_t *len);
extern const char* luaX_optlstring (lua_State *L, int narg, const char *argname, size_t *len, const char *def);
extern void* luaX_checkudata (lua_State *L, int narg, const char *tname, const char *argname);
extern void* luaX_optudata (lua_State *L, int narg, const char *tname, const char *argname, void *def);
extern bool luaX_isclass (lua_State *L, int narg, const char *cname);
extern void* luaX_testclass (lua_State *L, int narg, const char *cname);
extern void* luaX_checkclass (lua_State *L, int narg, const char *cname, const char *argname);
extern void* luaX_optclass (lua_State *L, int narg, const char *cname, const char *argname, void *def);
static inline const char* luaX_checkstring (lua_State *L, int narg, const char *argname) {
return luaX_checklstring(L, narg, argname, NULL);
}
static inline const char* luaX_optstring (lua_State *L, int narg, const char *argname, const char *def) {
return luaX_optlstring(L, narg, argname, NULL, def);
}
#endif