diff options
author | Mike Pall <mike> | 2009-12-08 19:49:20 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-08 19:49:20 +0100 |
commit | 1d1fed48a002dfc0919135911057ebc255a53e0a (patch) | |
tree | c5c6643908374bb8f02f4c7691332d32f6645986 /src/lib_aux.c | |
parent | 55b16959717084884fd4a0cbae6d19e3786c20c7 (diff) | |
download | luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.gz luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.bz2 luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.zip |
RELEASE LuaJIT-2.0.0-beta2v2.0.0-beta2
Diffstat (limited to 'src/lib_aux.c')
-rw-r--r-- | src/lib_aux.c | 96 |
1 files changed, 5 insertions, 91 deletions
diff --git a/src/lib_aux.c b/src/lib_aux.c index 1ae32dbc..2bd06fbb 100644 --- a/src/lib_aux.c +++ b/src/lib_aux.c | |||
@@ -20,97 +20,6 @@ | |||
20 | #include "lj_err.h" | 20 | #include "lj_err.h" |
21 | #include "lj_lib.h" | 21 | #include "lj_lib.h" |
22 | 22 | ||
23 | /* convert a stack index to positive */ | ||
24 | #define abs_index(L, i) \ | ||
25 | ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) | ||
26 | |||
27 | /* -- Type checks --------------------------------------------------------- */ | ||
28 | |||
29 | LUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg) | ||
30 | { | ||
31 | if (!lua_checkstack(L, size)) | ||
32 | lj_err_callerv(L, LJ_ERR_STKOVM, msg); | ||
33 | } | ||
34 | |||
35 | LUALIB_API void luaL_checktype(lua_State *L, int narg, int tt) | ||
36 | { | ||
37 | if (lua_type(L, narg) != tt) | ||
38 | lj_err_argt(L, narg, tt); | ||
39 | } | ||
40 | |||
41 | LUALIB_API void luaL_checkany(lua_State *L, int narg) | ||
42 | { | ||
43 | lj_lib_checkany(L, narg); | ||
44 | } | ||
45 | |||
46 | LUALIB_API const char *luaL_checklstring(lua_State *L, int narg, size_t *len) | ||
47 | { | ||
48 | GCstr *s = lj_lib_checkstr(L, narg); | ||
49 | if (len != NULL) *len = s->len; | ||
50 | return strdata(s); | ||
51 | } | ||
52 | |||
53 | LUALIB_API const char *luaL_optlstring(lua_State *L, int narg, | ||
54 | const char *def, size_t *len) | ||
55 | { | ||
56 | GCstr *s = lj_lib_optstr(L, narg); | ||
57 | if (s) { | ||
58 | if (len != NULL) *len = s->len; | ||
59 | return strdata(s); | ||
60 | } | ||
61 | if (len != NULL) *len = def ? strlen(def) : 0; | ||
62 | return def; | ||
63 | } | ||
64 | |||
65 | LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg) | ||
66 | { | ||
67 | return lj_lib_checknum(L, narg); | ||
68 | } | ||
69 | |||
70 | LUALIB_API lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def) | ||
71 | { | ||
72 | lj_lib_opt(L, narg, | ||
73 | return lj_lib_checknum(L, narg); | ||
74 | , | ||
75 | return def; | ||
76 | ) | ||
77 | } | ||
78 | |||
79 | LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg) | ||
80 | { | ||
81 | #if LJ_64 | ||
82 | return (lua_Integer)lj_lib_checknum(L, narg); | ||
83 | #else | ||
84 | return lj_lib_checkint(L, narg); | ||
85 | #endif | ||
86 | } | ||
87 | |||
88 | LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def) | ||
89 | { | ||
90 | #if LJ_64 | ||
91 | lj_lib_opt(L, narg, | ||
92 | return (lua_Integer)lj_lib_checknum(L, narg); | ||
93 | , | ||
94 | return def; | ||
95 | ) | ||
96 | #else | ||
97 | return lj_lib_optint(L, narg, def); | ||
98 | #endif | ||
99 | } | ||
100 | |||
101 | LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, | ||
102 | const char *const lst[]) | ||
103 | { | ||
104 | GCstr *s = lj_lib_optstr(L, narg); | ||
105 | const char *opt = s ? strdata(s) : def; | ||
106 | uint32_t i; | ||
107 | if (!opt) lj_err_argt(L, narg, LUA_TSTRING); | ||
108 | for (i = 0; lst[i]; i++) | ||
109 | if (strcmp(lst[i], opt) == 0) | ||
110 | return (int)i; | ||
111 | lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt); | ||
112 | } | ||
113 | |||
114 | /* -- Module registration ------------------------------------------------- */ | 23 | /* -- Module registration ------------------------------------------------- */ |
115 | 24 | ||
116 | LUALIB_API const char *luaL_findtable(lua_State *L, int idx, | 25 | LUALIB_API const char *luaL_findtable(lua_State *L, int idx, |
@@ -149,6 +58,7 @@ static int libsize(const luaL_Reg *l) | |||
149 | LUALIB_API void luaL_openlib(lua_State *L, const char *libname, | 58 | LUALIB_API void luaL_openlib(lua_State *L, const char *libname, |
150 | const luaL_Reg *l, int nup) | 59 | const luaL_Reg *l, int nup) |
151 | { | 60 | { |
61 | lj_lib_checkfpu(L); | ||
152 | if (libname) { | 62 | if (libname) { |
153 | int size = libsize(l); | 63 | int size = libsize(l); |
154 | /* check whether lib already exists */ | 64 | /* check whether lib already exists */ |
@@ -285,6 +195,10 @@ LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B) | |||
285 | 195 | ||
286 | #define FREELIST_REF 0 | 196 | #define FREELIST_REF 0 |
287 | 197 | ||
198 | /* Convert a stack index to an absolute index. */ | ||
199 | #define abs_index(L, i) \ | ||
200 | ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) | ||
201 | |||
288 | LUALIB_API int luaL_ref(lua_State *L, int t) | 202 | LUALIB_API int luaL_ref(lua_State *L, int t) |
289 | { | 203 | { |
290 | int ref; | 204 | int ref; |