diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 13:41:38 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 13:41:38 -0200 |
| commit | 097edd388494bf8d294adb101b9c5fda688813e1 (patch) | |
| tree | ecf43d85ab01e5c939ae7b125befc15b9fa23c27 | |
| parent | 5c5d9b27031f0a7fcf61df86cd242105c38485d6 (diff) | |
| download | lua-097edd388494bf8d294adb101b9c5fda688813e1.tar.gz lua-097edd388494bf8d294adb101b9c5fda688813e1.tar.bz2 lua-097edd388494bf8d294adb101b9c5fda688813e1.zip | |
better names for auxiliar functions
| -rw-r--r-- | lauxlib.c | 51 | ||||
| -rw-r--r-- | lauxlib.h | 53 | ||||
| -rw-r--r-- | lbaselib.c | 84 | ||||
| -rw-r--r-- | ldblib.c | 24 | ||||
| -rw-r--r-- | liolib.c | 77 | ||||
| -rw-r--r-- | lmathlib.c | 67 | ||||
| -rw-r--r-- | lstrlib.c | 64 | ||||
| -rw-r--r-- | ltablib.c | 34 | ||||
| -rw-r--r-- | ltests.c | 64 |
9 files changed, 265 insertions, 253 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.88 2002/10/16 20:41:35 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.89 2002/10/22 18:07:55 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -93,25 +93,25 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | 95 | ||
| 96 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { | 96 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { |
| 97 | if (!lua_checkstack(L, space)) | 97 | if (!lua_checkstack(L, space)) |
| 98 | luaL_error(L, "stack overflow (%s)", mes); | 98 | luaL_error(L, "stack overflow (%s)", mes); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t) { | 102 | LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { |
| 103 | if (lua_type(L, narg) != t) | 103 | if (lua_type(L, narg) != t) |
| 104 | tag_error(L, narg, t); | 104 | tag_error(L, narg, t); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | LUALIB_API void luaL_check_any (lua_State *L, int narg) { | 108 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { |
| 109 | if (lua_type(L, narg) == LUA_TNONE) | 109 | if (lua_type(L, narg) == LUA_TNONE) |
| 110 | luaL_argerror(L, narg, "value expected"); | 110 | luaL_argerror(L, narg, "value expected"); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | 114 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { |
| 115 | const char *s = lua_tostring(L, narg); | 115 | const char *s = lua_tostring(L, narg); |
| 116 | if (!s) tag_error(L, narg, LUA_TSTRING); | 116 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| 117 | if (len) *len = lua_strlen(L, narg); | 117 | if (len) *len = lua_strlen(L, narg); |
| @@ -119,17 +119,18 @@ LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | |||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { | 122 | LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, |
| 123 | const char *def, size_t *len) { | ||
| 123 | if (lua_isnoneornil(L, narg)) { | 124 | if (lua_isnoneornil(L, narg)) { |
| 124 | if (len) | 125 | if (len) |
| 125 | *len = (def ? strlen(def) : 0); | 126 | *len = (def ? strlen(def) : 0); |
| 126 | return def; | 127 | return def; |
| 127 | } | 128 | } |
| 128 | else return luaL_check_lstr(L, narg, len); | 129 | else return luaL_checklstring(L, narg, len); |
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | 132 | ||
| 132 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) { | 133 | LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { |
| 133 | lua_Number d = lua_tonumber(L, narg); | 134 | lua_Number d = lua_tonumber(L, narg); |
| 134 | if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ | 135 | if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ |
| 135 | tag_error(L, narg, LUA_TNUMBER); | 136 | tag_error(L, narg, LUA_TNUMBER); |
| @@ -137,9 +138,9 @@ LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) { | |||
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | 140 | ||
| 140 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) { | 141 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { |
| 141 | if (lua_isnoneornil(L, narg)) return def; | 142 | if (lua_isnoneornil(L, narg)) return def; |
| 142 | else return luaL_check_number(L, narg); | 143 | else return luaL_checknumber(L, narg); |
| 143 | } | 144 | } |
| 144 | 145 | ||
| 145 | 146 | ||
| @@ -165,7 +166,17 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { | |||
| 165 | } | 166 | } |
| 166 | 167 | ||
| 167 | 168 | ||
| 168 | LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int nup) { | 169 | LUALIB_API void luaL_openlib (lua_State *L, const char *libname, |
| 170 | const luaL_reg *l, int nup) { | ||
| 171 | if (libname) { | ||
| 172 | lua_pushstring(L, libname); | ||
| 173 | lua_gettable(L, LUA_GLOBALSINDEX); /* check whether lib already exists */ | ||
| 174 | if (lua_isnil(L, -1)) { /* no? */ | ||
| 175 | lua_pop(L, 1); | ||
| 176 | lua_newtable(L); /* create it */ | ||
| 177 | } | ||
| 178 | lua_insert(L, -(nup+1)); /* move library table to below upvalues */ | ||
| 179 | } | ||
| 169 | for (; l->name; l++) { | 180 | for (; l->name; l++) { |
| 170 | int i; | 181 | int i; |
| 171 | lua_pushstring(L, l->name); | 182 | lua_pushstring(L, l->name); |
| @@ -174,18 +185,12 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int nup) { | |||
| 174 | lua_pushcclosure(L, l->func, nup); | 185 | lua_pushcclosure(L, l->func, nup); |
| 175 | lua_settable(L, -(nup+3)); | 186 | lua_settable(L, -(nup+3)); |
| 176 | } | 187 | } |
| 177 | lua_pop(L, nup); | 188 | lua_pop(L, nup); /* remove upvalues */ |
| 178 | } | 189 | if (libname) { |
| 179 | 190 | lua_pushstring(L, libname); | |
| 180 | 191 | lua_pushvalue(L, -2); | |
| 181 | LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, | 192 | lua_settable(L, LUA_GLOBALSINDEX); |
| 182 | const luaL_reg *l, int nup) { | 193 | } |
| 183 | lua_pushstring(L, libname); | ||
| 184 | lua_insert(L, -(nup+1)); | ||
| 185 | lua_newtable(L); | ||
| 186 | lua_insert(L, -(nup+1)); | ||
| 187 | luaL_openlib(L, l, nup); | ||
| 188 | lua_settable(L, LUA_GLOBALSINDEX); | ||
| 189 | } | 194 | } |
| 190 | 195 | ||
| 191 | 196 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.53 2002/08/30 20:00:59 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.54 2002/09/16 19:49:45 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -27,22 +27,21 @@ typedef struct luaL_reg { | |||
| 27 | } luaL_reg; | 27 | } luaL_reg; |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int nup); | 30 | LUALIB_API void luaL_openlib (lua_State *L, const char *libname, |
| 31 | LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, | 31 | const luaL_reg *l, int nup); |
| 32 | const luaL_reg *l, int nup); | ||
| 33 | LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *e); | 32 | LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *e); |
| 34 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e); | 33 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e); |
| 35 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname); | 34 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname); |
| 36 | LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg); | 35 | LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg); |
| 37 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *l); | 36 | LUALIB_API const char *luaL_checklstring (lua_State *L, int numArg, size_t *l); |
| 38 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, | 37 | LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg, |
| 39 | const char *def, size_t *l); | 38 | const char *def, size_t *l); |
| 40 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); | 39 | LUALIB_API lua_Number luaL_checknumber (lua_State *L, int numArg); |
| 41 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); | 40 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number def); |
| 42 | 41 | ||
| 43 | LUALIB_API void luaL_check_stack (lua_State *L, int sz, const char *msg); | 42 | LUALIB_API void luaL_checkstack (lua_State *L, int sz, const char *msg); |
| 44 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t); | 43 | LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); |
| 45 | LUALIB_API void luaL_check_any (lua_State *L, int narg); | 44 | LUALIB_API void luaL_checkany (lua_State *L, int narg); |
| 46 | 45 | ||
| 47 | LUALIB_API void luaL_where (lua_State *L, int lvl); | 46 | LUALIB_API void luaL_where (lua_State *L, int lvl); |
| 48 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...); | 47 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...); |
| @@ -64,14 +63,14 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t sz, | |||
| 64 | ** =============================================================== | 63 | ** =============================================================== |
| 65 | */ | 64 | */ |
| 66 | 65 | ||
| 67 | #define luaL_arg_check(L, cond,numarg,extramsg) if (!(cond)) \ | 66 | #define luaL_argcheck(L, cond,numarg,extramsg) if (!(cond)) \ |
| 68 | luaL_argerror(L, numarg,extramsg) | 67 | luaL_argerror(L, numarg,extramsg) |
| 69 | #define luaL_check_string(L,n) (luaL_check_lstr(L, (n), NULL)) | 68 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
| 70 | #define luaL_opt_string(L,n,d) (luaL_opt_lstr(L, (n), (d), NULL)) | 69 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
| 71 | #define luaL_check_int(L,n) ((int)luaL_check_number(L, n)) | 70 | #define luaL_checkint(L,n) ((int)luaL_checknumber(L, n)) |
| 72 | #define luaL_check_long(L,n) ((long)luaL_check_number(L, n)) | 71 | #define luaL_checklong(L,n) ((long)luaL_checknumber(L, n)) |
| 73 | #define luaL_opt_int(L,n,d) ((int)luaL_opt_number(L, n,d)) | 72 | #define luaL_optint(L,n,d) ((int)luaL_optnumber(L, n,d)) |
| 74 | #define luaL_opt_long(L,n,d) ((long)luaL_opt_number(L, n,d)) | 73 | #define luaL_optlong(L,n,d) ((long)luaL_optnumber(L, n,d)) |
| 75 | 74 | ||
| 76 | 75 | ||
| 77 | /* | 76 | /* |
| @@ -115,14 +114,24 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B); | |||
| 115 | ** Compatibility macros | 114 | ** Compatibility macros |
| 116 | */ | 115 | */ |
| 117 | 116 | ||
| 118 | #define luaL_checktype luaL_check_type | ||
| 119 | #define luaL_checkany luaL_check_any | ||
| 120 | |||
| 121 | LUALIB_API int lua_dofile (lua_State *L, const char *filename); | 117 | LUALIB_API int lua_dofile (lua_State *L, const char *filename); |
| 122 | LUALIB_API int lua_dostring (lua_State *L, const char *str); | 118 | LUALIB_API int lua_dostring (lua_State *L, const char *str); |
| 123 | LUALIB_API int lua_dobuffer (lua_State *L, const char *buff, size_t sz, | 119 | LUALIB_API int lua_dobuffer (lua_State *L, const char *buff, size_t sz, |
| 124 | const char *n); | 120 | const char *n); |
| 125 | 121 | ||
| 122 | /* | ||
| 123 | #define luaL_check_lstr luaL_checklstring | ||
| 124 | #define luaL_opt_lstr luaL_optlstring | ||
| 125 | #define luaL_check_number luaL_checknumber | ||
| 126 | #define luaL_opt_number luaL_optnumber | ||
| 127 | #define luaL_arg_check luaL_argcheck | ||
| 128 | #define luaL_check_string luaL_checkstring | ||
| 129 | #define luaL_opt_string luaL_optstring | ||
| 130 | #define luaL_check_int luaL_checkint | ||
| 131 | #define luaL_check_long luaL_checklong | ||
| 132 | #define luaL_opt_int luaL_optint | ||
| 133 | #define luaL_opt_long luaL_optlong | ||
| 134 | */ | ||
| 126 | 135 | ||
| 127 | #endif | 136 | #endif |
| 128 | 137 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.105 2002/11/07 15:39:23 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.106 2002/11/14 12:01:35 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -47,19 +47,19 @@ static int luaB_print (lua_State *L) { | |||
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | static int luaB_tonumber (lua_State *L) { | 49 | static int luaB_tonumber (lua_State *L) { |
| 50 | int base = luaL_opt_int(L, 2, 10); | 50 | int base = luaL_optint(L, 2, 10); |
| 51 | if (base == 10) { /* standard conversion */ | 51 | if (base == 10) { /* standard conversion */ |
| 52 | luaL_check_any(L, 1); | 52 | luaL_checkany(L, 1); |
| 53 | if (lua_isnumber(L, 1)) { | 53 | if (lua_isnumber(L, 1)) { |
| 54 | lua_pushnumber(L, lua_tonumber(L, 1)); | 54 | lua_pushnumber(L, lua_tonumber(L, 1)); |
| 55 | return 1; | 55 | return 1; |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | else { | 58 | else { |
| 59 | const char *s1 = luaL_check_string(L, 1); | 59 | const char *s1 = luaL_checkstring(L, 1); |
| 60 | char *s2; | 60 | char *s2; |
| 61 | unsigned long n; | 61 | unsigned long n; |
| 62 | luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); | 62 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
| 63 | n = strtoul(s1, &s2, base); | 63 | n = strtoul(s1, &s2, base); |
| 64 | if (s1 != s2) { /* at least one valid digit? */ | 64 | if (s1 != s2) { /* at least one valid digit? */ |
| 65 | while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ | 65 | while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ |
| @@ -75,8 +75,8 @@ static int luaB_tonumber (lua_State *L) { | |||
| 75 | 75 | ||
| 76 | 76 | ||
| 77 | static int luaB_error (lua_State *L) { | 77 | static int luaB_error (lua_State *L) { |
| 78 | int level = luaL_opt_int(L, 2, 1); | 78 | int level = luaL_optint(L, 2, 1); |
| 79 | luaL_check_any(L, 1); | 79 | luaL_checkany(L, 1); |
| 80 | if (!lua_isstring(L, 1) || level == 0) | 80 | if (!lua_isstring(L, 1) || level == 0) |
| 81 | lua_pushvalue(L, 1); /* propagate error mesage without changes */ | 81 | lua_pushvalue(L, 1); /* propagate error mesage without changes */ |
| 82 | else { /* add extra information */ | 82 | else { /* add extra information */ |
| @@ -89,7 +89,7 @@ static int luaB_error (lua_State *L) { | |||
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | static int luaB_getmetatable (lua_State *L) { | 91 | static int luaB_getmetatable (lua_State *L) { |
| 92 | luaL_check_any(L, 1); | 92 | luaL_checkany(L, 1); |
| 93 | if (!lua_getmetatable(L, 1)) { | 93 | if (!lua_getmetatable(L, 1)) { |
| 94 | lua_pushnil(L); | 94 | lua_pushnil(L); |
| 95 | return 1; /* no metatable */ | 95 | return 1; /* no metatable */ |
| @@ -101,8 +101,8 @@ static int luaB_getmetatable (lua_State *L) { | |||
| 101 | 101 | ||
| 102 | static int luaB_setmetatable (lua_State *L) { | 102 | static int luaB_setmetatable (lua_State *L) { |
| 103 | int t = lua_type(L, 2); | 103 | int t = lua_type(L, 2); |
| 104 | luaL_check_type(L, 1, LUA_TTABLE); | 104 | luaL_checktype(L, 1, LUA_TTABLE); |
| 105 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, | 105 | luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, |
| 106 | "nil or table expected"); | 106 | "nil or table expected"); |
| 107 | if (luaL_getmetafield(L, 1, "__metatable")) | 107 | if (luaL_getmetafield(L, 1, "__metatable")) |
| 108 | luaL_error(L, "cannot change a protected metatable"); | 108 | luaL_error(L, "cannot change a protected metatable"); |
| @@ -116,8 +116,8 @@ static void getfunc (lua_State *L) { | |||
| 116 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); | 116 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); |
| 117 | else { | 117 | else { |
| 118 | lua_Debug ar; | 118 | lua_Debug ar; |
| 119 | int level = luaL_opt_int(L, 1, 1); | 119 | int level = luaL_optint(L, 1, 1); |
| 120 | luaL_arg_check(L, level >= 0, 1, "level must be non-negative"); | 120 | luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); |
| 121 | if (lua_getstack(L, level, &ar) == 0) | 121 | if (lua_getstack(L, level, &ar) == 0) |
| 122 | luaL_argerror(L, 1, "invalid level"); | 122 | luaL_argerror(L, 1, "invalid level"); |
| 123 | lua_getinfo(L, "f", &ar); | 123 | lua_getinfo(L, "f", &ar); |
| @@ -142,7 +142,7 @@ static int luaB_getglobals (lua_State *L) { | |||
| 142 | 142 | ||
| 143 | 143 | ||
| 144 | static int luaB_setglobals (lua_State *L) { | 144 | static int luaB_setglobals (lua_State *L) { |
| 145 | luaL_check_type(L, 2, LUA_TTABLE); | 145 | luaL_checktype(L, 2, LUA_TTABLE); |
| 146 | getfunc(L); | 146 | getfunc(L); |
| 147 | if (aux_getglobals(L)) /* __globals defined? */ | 147 | if (aux_getglobals(L)) /* __globals defined? */ |
| 148 | luaL_error(L, "cannot change a protected global table"); | 148 | luaL_error(L, "cannot change a protected global table"); |
| @@ -156,24 +156,24 @@ static int luaB_setglobals (lua_State *L) { | |||
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | static int luaB_rawequal (lua_State *L) { | 158 | static int luaB_rawequal (lua_State *L) { |
| 159 | luaL_check_any(L, 1); | 159 | luaL_checkany(L, 1); |
| 160 | luaL_check_any(L, 2); | 160 | luaL_checkany(L, 2); |
| 161 | lua_pushboolean(L, lua_rawequal(L, 1, 2)); | 161 | lua_pushboolean(L, lua_rawequal(L, 1, 2)); |
| 162 | return 1; | 162 | return 1; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | 165 | ||
| 166 | static int luaB_rawget (lua_State *L) { | 166 | static int luaB_rawget (lua_State *L) { |
| 167 | luaL_check_type(L, 1, LUA_TTABLE); | 167 | luaL_checktype(L, 1, LUA_TTABLE); |
| 168 | luaL_check_any(L, 2); | 168 | luaL_checkany(L, 2); |
| 169 | lua_rawget(L, 1); | 169 | lua_rawget(L, 1); |
| 170 | return 1; | 170 | return 1; |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | static int luaB_rawset (lua_State *L) { | 173 | static int luaB_rawset (lua_State *L) { |
| 174 | luaL_check_type(L, 1, LUA_TTABLE); | 174 | luaL_checktype(L, 1, LUA_TTABLE); |
| 175 | luaL_check_any(L, 2); | 175 | luaL_checkany(L, 2); |
| 176 | luaL_check_any(L, 3); | 176 | luaL_checkany(L, 3); |
| 177 | lua_rawset(L, 1); | 177 | lua_rawset(L, 1); |
| 178 | return 1; | 178 | return 1; |
| 179 | } | 179 | } |
| @@ -187,20 +187,20 @@ static int luaB_gcinfo (lua_State *L) { | |||
| 187 | 187 | ||
| 188 | 188 | ||
| 189 | static int luaB_collectgarbage (lua_State *L) { | 189 | static int luaB_collectgarbage (lua_State *L) { |
| 190 | lua_setgcthreshold(L, luaL_opt_int(L, 1, 0)); | 190 | lua_setgcthreshold(L, luaL_optint(L, 1, 0)); |
| 191 | return 0; | 191 | return 0; |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | 194 | ||
| 195 | static int luaB_type (lua_State *L) { | 195 | static int luaB_type (lua_State *L) { |
| 196 | luaL_check_any(L, 1); | 196 | luaL_checkany(L, 1); |
| 197 | lua_pushstring(L, lua_typename(L, lua_type(L, 1))); | 197 | lua_pushstring(L, lua_typename(L, lua_type(L, 1))); |
| 198 | return 1; | 198 | return 1; |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | static int luaB_next (lua_State *L) { | 202 | static int luaB_next (lua_State *L) { |
| 203 | luaL_check_type(L, 1, LUA_TTABLE); | 203 | luaL_checktype(L, 1, LUA_TTABLE); |
| 204 | lua_settop(L, 2); /* create a 2nd argument if there isn't one */ | 204 | lua_settop(L, 2); /* create a 2nd argument if there isn't one */ |
| 205 | if (lua_next(L, 1)) | 205 | if (lua_next(L, 1)) |
| 206 | return 2; | 206 | return 2; |
| @@ -212,7 +212,7 @@ static int luaB_next (lua_State *L) { | |||
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | static int luaB_pairs (lua_State *L) { | 214 | static int luaB_pairs (lua_State *L) { |
| 215 | luaL_check_type(L, 1, LUA_TTABLE); | 215 | luaL_checktype(L, 1, LUA_TTABLE); |
| 216 | lua_getglobal(L, "next"); /* return generator, */ | 216 | lua_getglobal(L, "next"); /* return generator, */ |
| 217 | lua_pushvalue(L, 1); /* state, */ | 217 | lua_pushvalue(L, 1); /* state, */ |
| 218 | lua_pushnil(L); /* and initial value */ | 218 | lua_pushnil(L); /* and initial value */ |
| @@ -222,7 +222,7 @@ static int luaB_pairs (lua_State *L) { | |||
| 222 | 222 | ||
| 223 | static int luaB_ipairs (lua_State *L) { | 223 | static int luaB_ipairs (lua_State *L) { |
| 224 | lua_Number i = lua_tonumber(L, 2); | 224 | lua_Number i = lua_tonumber(L, 2); |
| 225 | luaL_check_type(L, 1, LUA_TTABLE); | 225 | luaL_checktype(L, 1, LUA_TTABLE); |
| 226 | if (i == 0 && lua_isnull(L, 2)) { /* `for' start? */ | 226 | if (i == 0 && lua_isnull(L, 2)) { /* `for' start? */ |
| 227 | lua_getglobal(L, "ipairs"); /* return generator, */ | 227 | lua_getglobal(L, "ipairs"); /* return generator, */ |
| 228 | lua_pushvalue(L, 1); /* state, */ | 228 | lua_pushvalue(L, 1); /* state, */ |
| @@ -250,8 +250,8 @@ static int passresults (lua_State *L, int status) { | |||
| 250 | 250 | ||
| 251 | static int luaB_loadstring (lua_State *L) { | 251 | static int luaB_loadstring (lua_State *L) { |
| 252 | size_t l; | 252 | size_t l; |
| 253 | const char *s = luaL_check_lstr(L, 1, &l); | 253 | const char *s = luaL_checklstring(L, 1, &l); |
| 254 | const char *chunkname = luaL_opt_string(L, 2, s); | 254 | const char *chunkname = luaL_optstring(L, 2, s); |
| 255 | return passresults(L, luaL_loadbuffer(L, s, l, chunkname)); | 255 | return passresults(L, luaL_loadbuffer(L, s, l, chunkname)); |
| 256 | } | 256 | } |
| 257 | 257 | ||
| @@ -265,7 +265,7 @@ static int writer (lua_State *L, const void* b, size_t size, void* B) { | |||
| 265 | 265 | ||
| 266 | static int luaB_stringdump (lua_State *L) { | 266 | static int luaB_stringdump (lua_State *L) { |
| 267 | luaL_Buffer b; | 267 | luaL_Buffer b; |
| 268 | luaL_check_type(L, 1, LUA_TFUNCTION); | 268 | luaL_checktype(L, 1, LUA_TFUNCTION); |
| 269 | luaL_buffinit(L,&b); | 269 | luaL_buffinit(L,&b); |
| 270 | if (!lua_dump(L, writer, &b)) | 270 | if (!lua_dump(L, writer, &b)) |
| 271 | luaL_error(L, "unable to dump given function"); | 271 | luaL_error(L, "unable to dump given function"); |
| @@ -276,13 +276,13 @@ static int luaB_stringdump (lua_State *L) { | |||
| 276 | 276 | ||
| 277 | 277 | ||
| 278 | static int luaB_loadfile (lua_State *L) { | 278 | static int luaB_loadfile (lua_State *L) { |
| 279 | const char *fname = luaL_opt_string(L, 1, NULL); | 279 | const char *fname = luaL_optstring(L, 1, NULL); |
| 280 | return passresults(L, luaL_loadfile(L, fname)); | 280 | return passresults(L, luaL_loadfile(L, fname)); |
| 281 | } | 281 | } |
| 282 | 282 | ||
| 283 | 283 | ||
| 284 | static int luaB_dofile (lua_State *L) { | 284 | static int luaB_dofile (lua_State *L) { |
| 285 | const char *fname = luaL_opt_string(L, 1, NULL); | 285 | const char *fname = luaL_optstring(L, 1, NULL); |
| 286 | int status = luaL_loadfile(L, fname); | 286 | int status = luaL_loadfile(L, fname); |
| 287 | if (status != 0) lua_error(L); | 287 | if (status != 0) lua_error(L); |
| 288 | lua_call(L, 0, LUA_MULTRET); | 288 | lua_call(L, 0, LUA_MULTRET); |
| @@ -291,9 +291,9 @@ static int luaB_dofile (lua_State *L) { | |||
| 291 | 291 | ||
| 292 | 292 | ||
| 293 | static int luaB_assert (lua_State *L) { | 293 | static int luaB_assert (lua_State *L) { |
| 294 | luaL_check_any(L, 1); | 294 | luaL_checkany(L, 1); |
| 295 | if (!lua_toboolean(L, 1)) | 295 | if (!lua_toboolean(L, 1)) |
| 296 | return luaL_error(L, "%s", luaL_opt_string(L, 2, "assertion failed!")); | 296 | return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); |
| 297 | lua_settop(L, 1); | 297 | lua_settop(L, 1); |
| 298 | return 1; | 298 | return 1; |
| 299 | } | 299 | } |
| @@ -301,12 +301,12 @@ static int luaB_assert (lua_State *L) { | |||
| 301 | 301 | ||
| 302 | static int luaB_unpack (lua_State *L) { | 302 | static int luaB_unpack (lua_State *L) { |
| 303 | int n, i; | 303 | int n, i; |
| 304 | luaL_check_type(L, 1, LUA_TTABLE); | 304 | luaL_checktype(L, 1, LUA_TTABLE); |
| 305 | lua_pushliteral(L, "n"); | 305 | lua_pushliteral(L, "n"); |
| 306 | lua_rawget(L, 1); | 306 | lua_rawget(L, 1); |
| 307 | n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1; | 307 | n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1; |
| 308 | for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */ | 308 | for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */ |
| 309 | luaL_check_stack(L, LUA_MINSTACK, "table too big to unpack"); | 309 | luaL_checkstack(L, LUA_MINSTACK, "table too big to unpack"); |
| 310 | lua_rawgeti(L, 1, i+1); | 310 | lua_rawgeti(L, 1, i+1); |
| 311 | if (n == -1) { /* no explicit limit? */ | 311 | if (n == -1) { /* no explicit limit? */ |
| 312 | if (lua_isnil(L, -1)) { /* stop at first `nil' element */ | 312 | if (lua_isnil(L, -1)) { /* stop at first `nil' element */ |
| @@ -321,7 +321,7 @@ static int luaB_unpack (lua_State *L) { | |||
| 321 | 321 | ||
| 322 | static int luaB_pcall (lua_State *L) { | 322 | static int luaB_pcall (lua_State *L) { |
| 323 | int status; | 323 | int status; |
| 324 | luaL_check_any(L, 1); | 324 | luaL_checkany(L, 1); |
| 325 | status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); | 325 | status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); |
| 326 | lua_pushboolean(L, (status == 0)); | 326 | lua_pushboolean(L, (status == 0)); |
| 327 | lua_insert(L, 1); | 327 | lua_insert(L, 1); |
| @@ -331,7 +331,7 @@ static int luaB_pcall (lua_State *L) { | |||
| 331 | 331 | ||
| 332 | static int luaB_xpcall (lua_State *L) { | 332 | static int luaB_xpcall (lua_State *L) { |
| 333 | int status; | 333 | int status; |
| 334 | luaL_check_any(L, 2); | 334 | luaL_checkany(L, 2); |
| 335 | lua_settop(L, 2); | 335 | lua_settop(L, 2); |
| 336 | lua_insert(L, 1); /* put error function under function to be called */ | 336 | lua_insert(L, 1); /* put error function under function to be called */ |
| 337 | status = lua_pcall(L, 0, LUA_MULTRET, 1); | 337 | status = lua_pcall(L, 0, LUA_MULTRET, 1); |
| @@ -396,7 +396,7 @@ static int luaB_newproxy (lua_State *L) { | |||
| 396 | validproxy = lua_toboolean(L, -1); | 396 | validproxy = lua_toboolean(L, -1); |
| 397 | lua_pop(L, 1); /* remove value */ | 397 | lua_pop(L, 1); /* remove value */ |
| 398 | } | 398 | } |
| 399 | luaL_arg_check(L, validproxy, 1, "boolean/proxy expected"); | 399 | luaL_argcheck(L, validproxy, 1, "boolean/proxy expected"); |
| 400 | lua_getmetatable(L, 1); /* metatable is valid; get it */ | 400 | lua_getmetatable(L, 1); /* metatable is valid; get it */ |
| 401 | } | 401 | } |
| 402 | lua_setmetatable(L, 2); | 402 | lua_setmetatable(L, 2); |
| @@ -463,7 +463,7 @@ static void pushcomposename (lua_State *L) { | |||
| 463 | static int luaB_require (lua_State *L) { | 463 | static int luaB_require (lua_State *L) { |
| 464 | const char *path; | 464 | const char *path; |
| 465 | int status = LUA_ERRFILE; /* not found (yet) */ | 465 | int status = LUA_ERRFILE; /* not found (yet) */ |
| 466 | luaL_check_string(L, 1); | 466 | luaL_checkstring(L, 1); |
| 467 | lua_settop(L, 1); | 467 | lua_settop(L, 1); |
| 468 | lua_pushvalue(L, 1); | 468 | lua_pushvalue(L, 1); |
| 469 | lua_setglobal(L, "_REQUIREDNAME"); | 469 | lua_setglobal(L, "_REQUIREDNAME"); |
| @@ -563,7 +563,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { | |||
| 563 | static int luaB_coresume (lua_State *L) { | 563 | static int luaB_coresume (lua_State *L) { |
| 564 | lua_State *co = lua_tothread(L, 1); | 564 | lua_State *co = lua_tothread(L, 1); |
| 565 | int r; | 565 | int r; |
| 566 | luaL_arg_check(L, co, 1, "coroutine/thread expected"); | 566 | luaL_argcheck(L, co, 1, "coroutine/thread expected"); |
| 567 | r = auxresume(L, co, lua_gettop(L) - 1); | 567 | r = auxresume(L, co, lua_gettop(L) - 1); |
| 568 | if (r < 0) { | 568 | if (r < 0) { |
| 569 | lua_pushboolean(L, 0); | 569 | lua_pushboolean(L, 0); |
| @@ -588,7 +588,7 @@ static int luaB_auxwrap (lua_State *L) { | |||
| 588 | 588 | ||
| 589 | static int luaB_cocreate (lua_State *L) { | 589 | static int luaB_cocreate (lua_State *L) { |
| 590 | lua_State *NL = lua_newthread(L); | 590 | lua_State *NL = lua_newthread(L); |
| 591 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, | 591 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, |
| 592 | "Lua function expected"); | 592 | "Lua function expected"); |
| 593 | lua_pushvalue(L, 1); /* move function to top */ | 593 | lua_pushvalue(L, 1); /* move function to top */ |
| 594 | lua_xmove(L, NL, 1); /* move function from L to NL */ | 594 | lua_xmove(L, NL, 1); /* move function from L to NL */ |
| @@ -622,7 +622,7 @@ static const luaL_reg co_funcs[] = { | |||
| 622 | static void base_open (lua_State *L) { | 622 | static void base_open (lua_State *L) { |
| 623 | lua_pushliteral(L, "_G"); | 623 | lua_pushliteral(L, "_G"); |
| 624 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 624 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 625 | luaL_openlib(L, base_funcs, 0); /* open lib into global table */ | 625 | luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */ |
| 626 | lua_pushliteral(L, "_VERSION"); | 626 | lua_pushliteral(L, "_VERSION"); |
| 627 | lua_pushliteral(L, LUA_VERSION); | 627 | lua_pushliteral(L, LUA_VERSION); |
| 628 | lua_rawset(L, -3); /* set global _VERSION */ | 628 | lua_rawset(L, -3); /* set global _VERSION */ |
| @@ -642,7 +642,7 @@ static void base_open (lua_State *L) { | |||
| 642 | 642 | ||
| 643 | LUALIB_API int lua_baselibopen (lua_State *L) { | 643 | LUALIB_API int lua_baselibopen (lua_State *L) { |
| 644 | base_open(L); | 644 | base_open(L); |
| 645 | luaL_opennamedlib(L, LUA_COLIBNAME, co_funcs, 0); | 645 | luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0); |
| 646 | lua_newtable(L); | 646 | lua_newtable(L); |
| 647 | lua_setglobal(L, REQTAB); | 647 | lua_setglobal(L, REQTAB); |
| 648 | return 0; | 648 | return 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.69 2002/09/05 19:45:42 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.70 2002/09/16 19:18:01 roberto Exp roberto $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -32,7 +32,7 @@ static void settabsi (lua_State *L, const char *i, int v) { | |||
| 32 | 32 | ||
| 33 | static int getinfo (lua_State *L) { | 33 | static int getinfo (lua_State *L) { |
| 34 | lua_Debug ar; | 34 | lua_Debug ar; |
| 35 | const char *options = luaL_opt_string(L, 2, "flnSu"); | 35 | const char *options = luaL_optstring(L, 2, "flnSu"); |
| 36 | if (lua_isnumber(L, 1)) { | 36 | if (lua_isnumber(L, 1)) { |
| 37 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { | 37 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { |
| 38 | lua_pushnil(L); /* level out of range */ | 38 | lua_pushnil(L); /* level out of range */ |
| @@ -81,9 +81,9 @@ static int getinfo (lua_State *L) { | |||
| 81 | static int getlocal (lua_State *L) { | 81 | static int getlocal (lua_State *L) { |
| 82 | lua_Debug ar; | 82 | lua_Debug ar; |
| 83 | const char *name; | 83 | const char *name; |
| 84 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 84 | if (!lua_getstack(L, luaL_checkint(L, 1), &ar)) /* level out of range? */ |
| 85 | return luaL_argerror(L, 1, "level out of range"); | 85 | return luaL_argerror(L, 1, "level out of range"); |
| 86 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); | 86 | name = lua_getlocal(L, &ar, luaL_checkint(L, 2)); |
| 87 | if (name) { | 87 | if (name) { |
| 88 | lua_pushstring(L, name); | 88 | lua_pushstring(L, name); |
| 89 | lua_pushvalue(L, -2); | 89 | lua_pushvalue(L, -2); |
| @@ -98,10 +98,10 @@ static int getlocal (lua_State *L) { | |||
| 98 | 98 | ||
| 99 | static int setlocal (lua_State *L) { | 99 | static int setlocal (lua_State *L) { |
| 100 | lua_Debug ar; | 100 | lua_Debug ar; |
| 101 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 101 | if (!lua_getstack(L, luaL_checkint(L, 1), &ar)) /* level out of range? */ |
| 102 | return luaL_argerror(L, 1, "level out of range"); | 102 | return luaL_argerror(L, 1, "level out of range"); |
| 103 | luaL_check_any(L, 3); | 103 | luaL_checkany(L, 3); |
| 104 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); | 104 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_checkint(L, 2))); |
| 105 | return 1; | 105 | return 1; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| @@ -151,10 +151,10 @@ static int sethook (lua_State *L) { | |||
| 151 | lua_sethook(L, NULL, 0); /* turn off hooks */ | 151 | lua_sethook(L, NULL, 0); /* turn off hooks */ |
| 152 | } | 152 | } |
| 153 | else { | 153 | else { |
| 154 | const char *smask = luaL_check_string(L, 2); | 154 | const char *smask = luaL_checkstring(L, 2); |
| 155 | lua_Number count = luaL_opt_number(L, 3, 0); | 155 | lua_Number count = luaL_optnumber(L, 3, 0); |
| 156 | luaL_check_type(L, 1, LUA_TFUNCTION); | 156 | luaL_checktype(L, 1, LUA_TFUNCTION); |
| 157 | luaL_arg_check(L, count <= LUA_MAXCOUNT, 2, "count too large (>= 2^24)"); | 157 | luaL_argcheck(L, count <= LUA_MAXCOUNT, 2, "count too large (>= 2^24)"); |
| 158 | lua_sethook(L, hookf, makemask(smask, (int)count)); | 158 | lua_sethook(L, hookf, makemask(smask, (int)count)); |
| 159 | } | 159 | } |
| 160 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); | 160 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); |
| @@ -255,7 +255,7 @@ static const luaL_reg dblib[] = { | |||
| 255 | 255 | ||
| 256 | 256 | ||
| 257 | LUALIB_API int lua_dblibopen (lua_State *L) { | 257 | LUALIB_API int lua_dblibopen (lua_State *L) { |
| 258 | luaL_opennamedlib(L, LUA_DBLIBNAME, dblib, 0); | 258 | luaL_openlib(L, LUA_DBLIBNAME, dblib, 0); |
| 259 | lua_pushliteral(L, "_TRACEBACK"); | 259 | lua_pushliteral(L, "_TRACEBACK"); |
| 260 | lua_pushcfunction(L, errorfb); | 260 | lua_pushcfunction(L, errorfb); |
| 261 | lua_settable(L, LUA_GLOBALSINDEX); | 261 | lua_settable(L, LUA_GLOBALSINDEX); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.21 2002/10/16 20:41:35 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.22 2002/10/21 20:41:24 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -83,6 +83,10 @@ static FILE **newfile (lua_State *L) { | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | /* | ||
| 87 | ** assumes that top of the stack is the `io' library, and next is | ||
| 88 | ** the `io' metatable | ||
| 89 | */ | ||
| 86 | static void registerfile (lua_State *L, FILE *f, const char *name, | 90 | static void registerfile (lua_State *L, FILE *f, const char *name, |
| 87 | const char *impname) { | 91 | const char *impname) { |
| 88 | lua_pushstring(L, name); | 92 | lua_pushstring(L, name); |
| @@ -90,9 +94,9 @@ static void registerfile (lua_State *L, FILE *f, const char *name, | |||
| 90 | if (impname) { | 94 | if (impname) { |
| 91 | lua_pushstring(L, impname); | 95 | lua_pushstring(L, impname); |
| 92 | lua_pushvalue(L, -2); | 96 | lua_pushvalue(L, -2); |
| 93 | lua_settable(L, -6); | 97 | lua_settable(L, -6); /* metatable[impname] = file */ |
| 94 | } | 98 | } |
| 95 | lua_settable(L, -3); | 99 | lua_settable(L, -3); /* io[name] = file */ |
| 96 | } | 100 | } |
| 97 | 101 | ||
| 98 | 102 | ||
| @@ -127,8 +131,8 @@ static int io_gc (lua_State *L) { | |||
| 127 | 131 | ||
| 128 | 132 | ||
| 129 | static int io_open (lua_State *L) { | 133 | static int io_open (lua_State *L) { |
| 130 | const char *filename = luaL_check_string(L, 1); | 134 | const char *filename = luaL_checkstring(L, 1); |
| 131 | const char *mode = luaL_opt_string(L, 2, "r"); | 135 | const char *mode = luaL_optstring(L, 2, "r"); |
| 132 | FILE **pf = newfile(L); | 136 | FILE **pf = newfile(L); |
| 133 | *pf = fopen(filename, mode); | 137 | *pf = fopen(filename, mode); |
| 134 | return (*pf == NULL) ? pushresult(L, 0) : 1; | 138 | return (*pf == NULL) ? pushresult(L, 0) : 1; |
| @@ -140,8 +144,8 @@ static int io_popen (lua_State *L) { | |||
| 140 | luaL_error(L, "`popen' not supported"); | 144 | luaL_error(L, "`popen' not supported"); |
| 141 | return 0; | 145 | return 0; |
| 142 | #else | 146 | #else |
| 143 | const char *filename = luaL_check_string(L, 1); | 147 | const char *filename = luaL_checkstring(L, 1); |
| 144 | const char *mode = luaL_opt_string(L, 2, "r"); | 148 | const char *mode = luaL_optstring(L, 2, "r"); |
| 145 | FILE **pf = newfile(L); | 149 | FILE **pf = newfile(L); |
| 146 | *pf = popen(filename, mode); | 150 | *pf = popen(filename, mode); |
| 147 | return (*pf == NULL) ? pushresult(L, 0) : 1; | 151 | return (*pf == NULL) ? pushresult(L, 0) : 1; |
| @@ -179,7 +183,7 @@ static int g_iofile (lua_State *L, const char *name, const char *mode) { | |||
| 179 | if (filename) { | 183 | if (filename) { |
| 180 | FILE **pf = newfile(L); | 184 | FILE **pf = newfile(L); |
| 181 | *pf = fopen(filename, mode); | 185 | *pf = fopen(filename, mode); |
| 182 | luaL_arg_check(L, *pf, 1, strerror(errno)); | 186 | luaL_argcheck(L, *pf, 1, strerror(errno)); |
| 183 | } | 187 | } |
| 184 | else { | 188 | else { |
| 185 | tofile(L, 1); /* check that it's a valid file handle */ | 189 | tofile(L, 1); /* check that it's a valid file handle */ |
| @@ -227,10 +231,10 @@ static int io_lines (lua_State *L) { | |||
| 227 | return f_lines(L); | 231 | return f_lines(L); |
| 228 | } | 232 | } |
| 229 | else { | 233 | else { |
| 230 | const char *filename = luaL_check_string(L, 1); | 234 | const char *filename = luaL_checkstring(L, 1); |
| 231 | FILE **pf = newfile(L); | 235 | FILE **pf = newfile(L); |
| 232 | *pf = fopen(filename, "r"); | 236 | *pf = fopen(filename, "r"); |
| 233 | luaL_arg_check(L, *pf, 1, strerror(errno)); | 237 | luaL_argcheck(L, *pf, 1, strerror(errno)); |
| 234 | aux_lines(L, lua_gettop(L), 1); | 238 | aux_lines(L, lua_gettop(L), 1); |
| 235 | return 1; | 239 | return 1; |
| 236 | } | 240 | } |
| @@ -311,7 +315,7 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
| 311 | n = first+1; /* to return 1 result */ | 315 | n = first+1; /* to return 1 result */ |
| 312 | } | 316 | } |
| 313 | else { /* ensure stack space for all results and for auxlib's buffer */ | 317 | else { /* ensure stack space for all results and for auxlib's buffer */ |
| 314 | luaL_check_stack(L, nargs+LUA_MINSTACK, "too many arguments"); | 318 | luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); |
| 315 | success = 1; | 319 | success = 1; |
| 316 | for (n = first; nargs-- && success; n++) { | 320 | for (n = first; nargs-- && success; n++) { |
| 317 | if (lua_type(L, n) == LUA_TNUMBER) { | 321 | if (lua_type(L, n) == LUA_TNUMBER) { |
| @@ -388,7 +392,7 @@ static int g_write (lua_State *L, FILE *f, int arg) { | |||
| 388 | } | 392 | } |
| 389 | else { | 393 | else { |
| 390 | size_t l; | 394 | size_t l; |
| 391 | const char *s = luaL_check_lstr(L, arg, &l); | 395 | const char *s = luaL_checklstring(L, arg, &l); |
| 392 | status = status && (fwrite(s, sizeof(char), l, f) == l); | 396 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 393 | } | 397 | } |
| 394 | } | 398 | } |
| @@ -411,9 +415,9 @@ static int f_seek (lua_State *L) { | |||
| 411 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 415 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
| 412 | static const char *const modenames[] = {"set", "cur", "end", NULL}; | 416 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 413 | FILE *f = tofile(L, 1); | 417 | FILE *f = tofile(L, 1); |
| 414 | int op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); | 418 | int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames); |
| 415 | long offset = luaL_opt_long(L, 3, 0); | 419 | long offset = luaL_optlong(L, 3, 0); |
| 416 | luaL_arg_check(L, op != -1, 2, "invalid mode"); | 420 | luaL_argcheck(L, op != -1, 2, "invalid mode"); |
| 417 | op = fseek(f, offset, mode[op]); | 421 | op = fseek(f, offset, mode[op]); |
| 418 | if (op) | 422 | if (op) |
| 419 | return pushresult(L, 0); /* error */ | 423 | return pushresult(L, 0); /* error */ |
| @@ -473,7 +477,7 @@ static void createmeta (lua_State *L) { | |||
| 473 | lua_pushvalue(L, -2); /* push metatable */ | 477 | lua_pushvalue(L, -2); /* push metatable */ |
| 474 | lua_rawset(L, -3); /* metatable.__index = metatable */ | 478 | lua_rawset(L, -3); /* metatable.__index = metatable */ |
| 475 | lua_pushvalue(L, -1); /* push metatable (will be upvalue for library) */ | 479 | lua_pushvalue(L, -1); /* push metatable (will be upvalue for library) */ |
| 476 | luaL_openlib(L, flib, 1); | 480 | luaL_openlib(L, NULL, flib, 1); |
| 477 | lua_rawset(L, LUA_REGISTRYINDEX); /* registry.FILEHANDLE = metatable */ | 481 | lua_rawset(L, LUA_REGISTRYINDEX); /* registry.FILEHANDLE = metatable */ |
| 478 | } | 482 | } |
| 479 | 483 | ||
| @@ -487,19 +491,19 @@ static void createmeta (lua_State *L) { | |||
| 487 | */ | 491 | */ |
| 488 | 492 | ||
| 489 | static int io_execute (lua_State *L) { | 493 | static int io_execute (lua_State *L) { |
| 490 | lua_pushnumber(L, system(luaL_check_string(L, 1))); | 494 | lua_pushnumber(L, system(luaL_checkstring(L, 1))); |
| 491 | return 1; | 495 | return 1; |
| 492 | } | 496 | } |
| 493 | 497 | ||
| 494 | 498 | ||
| 495 | static int io_remove (lua_State *L) { | 499 | static int io_remove (lua_State *L) { |
| 496 | return pushresult(L, remove(luaL_check_string(L, 1)) == 0); | 500 | return pushresult(L, remove(luaL_checkstring(L, 1)) == 0); |
| 497 | } | 501 | } |
| 498 | 502 | ||
| 499 | 503 | ||
| 500 | static int io_rename (lua_State *L) { | 504 | static int io_rename (lua_State *L) { |
| 501 | return pushresult(L, rename(luaL_check_string(L, 1), | 505 | return pushresult(L, rename(luaL_checkstring(L, 1), |
| 502 | luaL_check_string(L, 2)) == 0); | 506 | luaL_checkstring(L, 2)) == 0); |
| 503 | } | 507 | } |
| 504 | 508 | ||
| 505 | 509 | ||
| @@ -513,7 +517,7 @@ static int io_tmpname (lua_State *L) { | |||
| 513 | 517 | ||
| 514 | 518 | ||
| 515 | static int io_getenv (lua_State *L) { | 519 | static int io_getenv (lua_State *L) { |
| 516 | lua_pushstring(L, getenv(luaL_check_string(L, 1))); /* if NULL push nil */ | 520 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ |
| 517 | return 1; | 521 | return 1; |
| 518 | } | 522 | } |
| 519 | 523 | ||
| @@ -571,8 +575,8 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
| 571 | 575 | ||
| 572 | 576 | ||
| 573 | static int io_date (lua_State *L) { | 577 | static int io_date (lua_State *L) { |
| 574 | const char *s = luaL_opt_string(L, 1, "%c"); | 578 | const char *s = luaL_optstring(L, 1, "%c"); |
| 575 | time_t t = (time_t)(luaL_opt_number(L, 2, -1)); | 579 | time_t t = (time_t)(luaL_optnumber(L, 2, -1)); |
| 576 | struct tm *stm; | 580 | struct tm *stm; |
| 577 | if (t == (time_t)(-1)) /* no time given? */ | 581 | if (t == (time_t)(-1)) /* no time given? */ |
| 578 | t = time(NULL); /* use current time */ | 582 | t = time(NULL); /* use current time */ |
| @@ -613,7 +617,7 @@ static int io_time (lua_State *L) { | |||
| 613 | else { | 617 | else { |
| 614 | time_t t; | 618 | time_t t; |
| 615 | struct tm ts; | 619 | struct tm ts; |
| 616 | luaL_check_type(L, 1, LUA_TTABLE); | 620 | luaL_checktype(L, 1, LUA_TTABLE); |
| 617 | lua_settop(L, 1); /* make sure table is at the top */ | 621 | lua_settop(L, 1); /* make sure table is at the top */ |
| 618 | ts.tm_sec = getfield(L, "sec", 0); | 622 | ts.tm_sec = getfield(L, "sec", 0); |
| 619 | ts.tm_min = getfield(L, "min", 0); | 623 | ts.tm_min = getfield(L, "min", 0); |
| @@ -633,8 +637,8 @@ static int io_time (lua_State *L) { | |||
| 633 | 637 | ||
| 634 | 638 | ||
| 635 | static int io_difftime (lua_State *L) { | 639 | static int io_difftime (lua_State *L) { |
| 636 | lua_pushnumber(L, difftime((time_t)(luaL_check_number(L, 1)), | 640 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), |
| 637 | (time_t)(luaL_opt_number(L, 2, 0)))); | 641 | (time_t)(luaL_optnumber(L, 2, 0)))); |
| 638 | return 1; | 642 | return 1; |
| 639 | } | 643 | } |
| 640 | 644 | ||
| @@ -647,16 +651,16 @@ static int io_setloc (lua_State *L) { | |||
| 647 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 651 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| 648 | "numeric", "time", NULL}; | 652 | "numeric", "time", NULL}; |
| 649 | const char *l = lua_tostring(L, 1); | 653 | const char *l = lua_tostring(L, 1); |
| 650 | int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); | 654 | int op = luaL_findstring(luaL_optstring(L, 2, "all"), catnames); |
| 651 | luaL_arg_check(L, l || lua_isnoneornil(L, 1), 1, "string expected"); | 655 | luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); |
| 652 | luaL_arg_check(L, op != -1, 2, "invalid option"); | 656 | luaL_argcheck(L, op != -1, 2, "invalid option"); |
| 653 | lua_pushstring(L, setlocale(cat[op], l)); | 657 | lua_pushstring(L, setlocale(cat[op], l)); |
| 654 | return 1; | 658 | return 1; |
| 655 | } | 659 | } |
| 656 | 660 | ||
| 657 | 661 | ||
| 658 | static int io_exit (lua_State *L) { | 662 | static int io_exit (lua_State *L) { |
| 659 | exit(luaL_opt_int(L, 1, EXIT_SUCCESS)); | 663 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); |
| 660 | return 0; /* to avoid warnings */ | 664 | return 0; /* to avoid warnings */ |
| 661 | } | 665 | } |
| 662 | 666 | ||
| @@ -681,18 +685,15 @@ static const luaL_reg syslib[] = { | |||
| 681 | 685 | ||
| 682 | LUALIB_API int lua_iolibopen (lua_State *L) { | 686 | LUALIB_API int lua_iolibopen (lua_State *L) { |
| 683 | createmeta(L); | 687 | createmeta(L); |
| 684 | luaL_opennamedlib(L, LUA_OSLIBNAME, syslib, 0); | 688 | luaL_openlib(L, LUA_OSLIBNAME, syslib, 0); |
| 685 | lua_pushliteral(L, FILEHANDLE); /* S: FH */ | 689 | lua_pushliteral(L, FILEHANDLE); |
| 686 | lua_rawget(L, LUA_REGISTRYINDEX); /* S: mt */ | 690 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 687 | lua_pushvalue(L, -1); /* S: mt mt */ | 691 | lua_pushvalue(L, -1); |
| 688 | luaL_opennamedlib(L, LUA_IOLIBNAME, iolib, 1); /* S: mt */ | 692 | luaL_openlib(L, LUA_IOLIBNAME, iolib, 1); |
| 689 | lua_pushliteral(L, LUA_IOLIBNAME); /* S: `io' mt */ | ||
| 690 | lua_gettable(L, LUA_GLOBALSINDEX); /* S: io mt */ | ||
| 691 | /* put predefined file handles into `io' table */ | 693 | /* put predefined file handles into `io' table */ |
| 692 | registerfile(L, stdin, "stdin", IO_INPUT); | 694 | registerfile(L, stdin, "stdin", IO_INPUT); |
| 693 | registerfile(L, stdout, "stdout", IO_OUTPUT); | 695 | registerfile(L, stdout, "stdout", IO_OUTPUT); |
| 694 | registerfile(L, stderr, "stderr", NULL); | 696 | registerfile(L, stderr, "stderr", NULL); |
| 695 | lua_pop(L, 2); /* S: empty */ | ||
| 696 | return 0; | 697 | return 0; |
| 697 | } | 698 | } |
| 698 | 699 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.50 2002/08/14 20:07:43 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.51 2002/08/14 20:10:33 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -34,104 +34,104 @@ | |||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | static int math_abs (lua_State *L) { | 36 | static int math_abs (lua_State *L) { |
| 37 | lua_pushnumber(L, fabs(luaL_check_number(L, 1))); | 37 | lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); |
| 38 | return 1; | 38 | return 1; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | static int math_sin (lua_State *L) { | 41 | static int math_sin (lua_State *L) { |
| 42 | lua_pushnumber(L, sin(TORAD(luaL_check_number(L, 1)))); | 42 | lua_pushnumber(L, sin(TORAD(luaL_checknumber(L, 1)))); |
| 43 | return 1; | 43 | return 1; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | static int math_cos (lua_State *L) { | 46 | static int math_cos (lua_State *L) { |
| 47 | lua_pushnumber(L, cos(TORAD(luaL_check_number(L, 1)))); | 47 | lua_pushnumber(L, cos(TORAD(luaL_checknumber(L, 1)))); |
| 48 | return 1; | 48 | return 1; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | static int math_tan (lua_State *L) { | 51 | static int math_tan (lua_State *L) { |
| 52 | lua_pushnumber(L, tan(TORAD(luaL_check_number(L, 1)))); | 52 | lua_pushnumber(L, tan(TORAD(luaL_checknumber(L, 1)))); |
| 53 | return 1; | 53 | return 1; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | static int math_asin (lua_State *L) { | 56 | static int math_asin (lua_State *L) { |
| 57 | lua_pushnumber(L, FROMRAD(asin(luaL_check_number(L, 1)))); | 57 | lua_pushnumber(L, FROMRAD(asin(luaL_checknumber(L, 1)))); |
| 58 | return 1; | 58 | return 1; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | static int math_acos (lua_State *L) { | 61 | static int math_acos (lua_State *L) { |
| 62 | lua_pushnumber(L, FROMRAD(acos(luaL_check_number(L, 1)))); | 62 | lua_pushnumber(L, FROMRAD(acos(luaL_checknumber(L, 1)))); |
| 63 | return 1; | 63 | return 1; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | static int math_atan (lua_State *L) { | 66 | static int math_atan (lua_State *L) { |
| 67 | lua_pushnumber(L, FROMRAD(atan(luaL_check_number(L, 1)))); | 67 | lua_pushnumber(L, FROMRAD(atan(luaL_checknumber(L, 1)))); |
| 68 | return 1; | 68 | return 1; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | static int math_atan2 (lua_State *L) { | 71 | static int math_atan2 (lua_State *L) { |
| 72 | lua_pushnumber(L, FROMRAD(atan2(luaL_check_number(L, 1), luaL_check_number(L, 2)))); | 72 | lua_pushnumber(L, FROMRAD(atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)))); |
| 73 | return 1; | 73 | return 1; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | static int math_ceil (lua_State *L) { | 76 | static int math_ceil (lua_State *L) { |
| 77 | lua_pushnumber(L, ceil(luaL_check_number(L, 1))); | 77 | lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); |
| 78 | return 1; | 78 | return 1; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | static int math_floor (lua_State *L) { | 81 | static int math_floor (lua_State *L) { |
| 82 | lua_pushnumber(L, floor(luaL_check_number(L, 1))); | 82 | lua_pushnumber(L, floor(luaL_checknumber(L, 1))); |
| 83 | return 1; | 83 | return 1; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | static int math_mod (lua_State *L) { | 86 | static int math_mod (lua_State *L) { |
| 87 | lua_pushnumber(L, fmod(luaL_check_number(L, 1), luaL_check_number(L, 2))); | 87 | lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); |
| 88 | return 1; | 88 | return 1; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | static int math_sqrt (lua_State *L) { | 91 | static int math_sqrt (lua_State *L) { |
| 92 | lua_pushnumber(L, sqrt(luaL_check_number(L, 1))); | 92 | lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); |
| 93 | return 1; | 93 | return 1; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | static int math_pow (lua_State *L) { | 96 | static int math_pow (lua_State *L) { |
| 97 | lua_pushnumber(L, pow(luaL_check_number(L, 1), luaL_check_number(L, 2))); | 97 | lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); |
| 98 | return 1; | 98 | return 1; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | static int math_log (lua_State *L) { | 101 | static int math_log (lua_State *L) { |
| 102 | lua_pushnumber(L, log(luaL_check_number(L, 1))); | 102 | lua_pushnumber(L, log(luaL_checknumber(L, 1))); |
| 103 | return 1; | 103 | return 1; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | static int math_log10 (lua_State *L) { | 106 | static int math_log10 (lua_State *L) { |
| 107 | lua_pushnumber(L, log10(luaL_check_number(L, 1))); | 107 | lua_pushnumber(L, log10(luaL_checknumber(L, 1))); |
| 108 | return 1; | 108 | return 1; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static int math_exp (lua_State *L) { | 111 | static int math_exp (lua_State *L) { |
| 112 | lua_pushnumber(L, exp(luaL_check_number(L, 1))); | 112 | lua_pushnumber(L, exp(luaL_checknumber(L, 1))); |
| 113 | return 1; | 113 | return 1; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static int math_deg (lua_State *L) { | 116 | static int math_deg (lua_State *L) { |
| 117 | lua_pushnumber(L, luaL_check_number(L, 1)/RADIANS_PER_DEGREE); | 117 | lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); |
| 118 | return 1; | 118 | return 1; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | static int math_rad (lua_State *L) { | 121 | static int math_rad (lua_State *L) { |
| 122 | lua_pushnumber(L, luaL_check_number(L, 1)*RADIANS_PER_DEGREE); | 122 | lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); |
| 123 | return 1; | 123 | return 1; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | static int math_frexp (lua_State *L) { | 126 | static int math_frexp (lua_State *L) { |
| 127 | int e; | 127 | int e; |
| 128 | lua_pushnumber(L, frexp(luaL_check_number(L, 1), &e)); | 128 | lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); |
| 129 | lua_pushnumber(L, e); | 129 | lua_pushnumber(L, e); |
| 130 | return 2; | 130 | return 2; |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | static int math_ldexp (lua_State *L) { | 133 | static int math_ldexp (lua_State *L) { |
| 134 | lua_pushnumber(L, ldexp(luaL_check_number(L, 1), luaL_check_int(L, 2))); | 134 | lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); |
| 135 | return 1; | 135 | return 1; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| @@ -139,10 +139,10 @@ static int math_ldexp (lua_State *L) { | |||
| 139 | 139 | ||
| 140 | static int math_min (lua_State *L) { | 140 | static int math_min (lua_State *L) { |
| 141 | int n = lua_gettop(L); /* number of arguments */ | 141 | int n = lua_gettop(L); /* number of arguments */ |
| 142 | lua_Number dmin = luaL_check_number(L, 1); | 142 | lua_Number dmin = luaL_checknumber(L, 1); |
| 143 | int i; | 143 | int i; |
| 144 | for (i=2; i<=n; i++) { | 144 | for (i=2; i<=n; i++) { |
| 145 | lua_Number d = luaL_check_number(L, i); | 145 | lua_Number d = luaL_checknumber(L, i); |
| 146 | if (d < dmin) | 146 | if (d < dmin) |
| 147 | dmin = d; | 147 | dmin = d; |
| 148 | } | 148 | } |
| @@ -153,10 +153,10 @@ static int math_min (lua_State *L) { | |||
| 153 | 153 | ||
| 154 | static int math_max (lua_State *L) { | 154 | static int math_max (lua_State *L) { |
| 155 | int n = lua_gettop(L); /* number of arguments */ | 155 | int n = lua_gettop(L); /* number of arguments */ |
| 156 | lua_Number dmax = luaL_check_number(L, 1); | 156 | lua_Number dmax = luaL_checknumber(L, 1); |
| 157 | int i; | 157 | int i; |
| 158 | for (i=2; i<=n; i++) { | 158 | for (i=2; i<=n; i++) { |
| 159 | lua_Number d = luaL_check_number(L, i); | 159 | lua_Number d = luaL_checknumber(L, i); |
| 160 | if (d > dmax) | 160 | if (d > dmax) |
| 161 | dmax = d; | 161 | dmax = d; |
| 162 | } | 162 | } |
| @@ -175,15 +175,15 @@ static int math_random (lua_State *L) { | |||
| 175 | break; | 175 | break; |
| 176 | } | 176 | } |
| 177 | case 1: { /* only upper limit */ | 177 | case 1: { /* only upper limit */ |
| 178 | int u = luaL_check_int(L, 1); | 178 | int u = luaL_checkint(L, 1); |
| 179 | luaL_arg_check(L, 1<=u, 1, "interval is empty"); | 179 | luaL_argcheck(L, 1<=u, 1, "interval is empty"); |
| 180 | lua_pushnumber(L, (int)floor(r*u)+1); /* int between 1 and `u' */ | 180 | lua_pushnumber(L, (int)floor(r*u)+1); /* int between 1 and `u' */ |
| 181 | break; | 181 | break; |
| 182 | } | 182 | } |
| 183 | case 2: { /* lower and upper limits */ | 183 | case 2: { /* lower and upper limits */ |
| 184 | int l = luaL_check_int(L, 1); | 184 | int l = luaL_checkint(L, 1); |
| 185 | int u = luaL_check_int(L, 2); | 185 | int u = luaL_checkint(L, 2); |
| 186 | luaL_arg_check(L, l<=u, 2, "interval is empty"); | 186 | luaL_argcheck(L, l<=u, 2, "interval is empty"); |
| 187 | lua_pushnumber(L, (int)floor(r*(u-l+1))+l); /* int between `l' and `u' */ | 187 | lua_pushnumber(L, (int)floor(r*(u-l+1))+l); /* int between `l' and `u' */ |
| 188 | break; | 188 | break; |
| 189 | } | 189 | } |
| @@ -194,7 +194,7 @@ static int math_random (lua_State *L) { | |||
| 194 | 194 | ||
| 195 | 195 | ||
| 196 | static int math_randomseed (lua_State *L) { | 196 | static int math_randomseed (lua_State *L) { |
| 197 | srand(luaL_check_int(L, 1)); | 197 | srand(luaL_checkint(L, 1)); |
| 198 | return 0; | 198 | return 0; |
| 199 | } | 199 | } |
| 200 | 200 | ||
| @@ -232,13 +232,10 @@ static const luaL_reg mathlib[] = { | |||
| 232 | ** Open math library | 232 | ** Open math library |
| 233 | */ | 233 | */ |
| 234 | LUALIB_API int lua_mathlibopen (lua_State *L) { | 234 | LUALIB_API int lua_mathlibopen (lua_State *L) { |
| 235 | lua_pushliteral(L, LUA_MATHLIBNAME); | 235 | luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0); |
| 236 | lua_newtable(L); | ||
| 237 | luaL_openlib(L, mathlib, 0); | ||
| 238 | lua_pushliteral(L, "pi"); | 236 | lua_pushliteral(L, "pi"); |
| 239 | lua_pushnumber(L, PI); | 237 | lua_pushnumber(L, PI); |
| 240 | lua_settable(L, -3); | 238 | lua_settable(L, -3); |
| 241 | lua_settable(L, LUA_GLOBALSINDEX); | ||
| 242 | lua_pushliteral(L, "__pow"); | 239 | lua_pushliteral(L, "__pow"); |
| 243 | lua_pushcfunction(L, math_pow); | 240 | lua_pushcfunction(L, math_pow); |
| 244 | lua_settable(L, LUA_REGISTRYINDEX); | 241 | lua_settable(L, LUA_REGISTRYINDEX); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.88 2002/08/21 19:39:31 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.89 2002/08/23 19:45:24 roberto Exp roberto $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -28,7 +28,7 @@ typedef long sint32; /* a signed version for size_t */ | |||
| 28 | 28 | ||
| 29 | static int str_len (lua_State *L) { | 29 | static int str_len (lua_State *L) { |
| 30 | size_t l; | 30 | size_t l; |
| 31 | luaL_check_lstr(L, 1, &l); | 31 | luaL_checklstring(L, 1, &l); |
| 32 | lua_pushnumber(L, l); | 32 | lua_pushnumber(L, l); |
| 33 | return 1; | 33 | return 1; |
| 34 | } | 34 | } |
| @@ -42,9 +42,9 @@ static sint32 posrelat (sint32 pos, size_t len) { | |||
| 42 | 42 | ||
| 43 | static int str_sub (lua_State *L) { | 43 | static int str_sub (lua_State *L) { |
| 44 | size_t l; | 44 | size_t l; |
| 45 | const char *s = luaL_check_lstr(L, 1, &l); | 45 | const char *s = luaL_checklstring(L, 1, &l); |
| 46 | sint32 start = posrelat(luaL_check_long(L, 2), l); | 46 | sint32 start = posrelat(luaL_checklong(L, 2), l); |
| 47 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); | 47 | sint32 end = posrelat(luaL_optlong(L, 3, -1), l); |
| 48 | if (start < 1) start = 1; | 48 | if (start < 1) start = 1; |
| 49 | if (end > (sint32)l) end = l; | 49 | if (end > (sint32)l) end = l; |
| 50 | if (start <= end) | 50 | if (start <= end) |
| @@ -58,7 +58,7 @@ static int str_lower (lua_State *L) { | |||
| 58 | size_t l; | 58 | size_t l; |
| 59 | size_t i; | 59 | size_t i; |
| 60 | luaL_Buffer b; | 60 | luaL_Buffer b; |
| 61 | const char *s = luaL_check_lstr(L, 1, &l); | 61 | const char *s = luaL_checklstring(L, 1, &l); |
| 62 | luaL_buffinit(L, &b); | 62 | luaL_buffinit(L, &b); |
| 63 | for (i=0; i<l; i++) | 63 | for (i=0; i<l; i++) |
| 64 | luaL_putchar(&b, tolower(uchar(s[i]))); | 64 | luaL_putchar(&b, tolower(uchar(s[i]))); |
| @@ -71,7 +71,7 @@ static int str_upper (lua_State *L) { | |||
| 71 | size_t l; | 71 | size_t l; |
| 72 | size_t i; | 72 | size_t i; |
| 73 | luaL_Buffer b; | 73 | luaL_Buffer b; |
| 74 | const char *s = luaL_check_lstr(L, 1, &l); | 74 | const char *s = luaL_checklstring(L, 1, &l); |
| 75 | luaL_buffinit(L, &b); | 75 | luaL_buffinit(L, &b); |
| 76 | for (i=0; i<l; i++) | 76 | for (i=0; i<l; i++) |
| 77 | luaL_putchar(&b, toupper(uchar(s[i]))); | 77 | luaL_putchar(&b, toupper(uchar(s[i]))); |
| @@ -82,8 +82,8 @@ static int str_upper (lua_State *L) { | |||
| 82 | static int str_rep (lua_State *L) { | 82 | static int str_rep (lua_State *L) { |
| 83 | size_t l; | 83 | size_t l; |
| 84 | luaL_Buffer b; | 84 | luaL_Buffer b; |
| 85 | const char *s = luaL_check_lstr(L, 1, &l); | 85 | const char *s = luaL_checklstring(L, 1, &l); |
| 86 | int n = luaL_check_int(L, 2); | 86 | int n = luaL_checkint(L, 2); |
| 87 | luaL_buffinit(L, &b); | 87 | luaL_buffinit(L, &b); |
| 88 | while (n-- > 0) | 88 | while (n-- > 0) |
| 89 | luaL_addlstring(&b, s, l); | 89 | luaL_addlstring(&b, s, l); |
| @@ -94,9 +94,9 @@ static int str_rep (lua_State *L) { | |||
| 94 | 94 | ||
| 95 | static int str_byte (lua_State *L) { | 95 | static int str_byte (lua_State *L) { |
| 96 | size_t l; | 96 | size_t l; |
| 97 | const char *s = luaL_check_lstr(L, 1, &l); | 97 | const char *s = luaL_checklstring(L, 1, &l); |
| 98 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); | 98 | sint32 pos = posrelat(luaL_optlong(L, 2, 1), l); |
| 99 | luaL_arg_check(L, 0 < pos && (size_t)(pos) <= l, 2, "out of range"); | 99 | luaL_argcheck(L, 0 < pos && (size_t)(pos) <= l, 2, "out of range"); |
| 100 | lua_pushnumber(L, uchar(s[pos-1])); | 100 | lua_pushnumber(L, uchar(s[pos-1])); |
| 101 | return 1; | 101 | return 1; |
| 102 | } | 102 | } |
| @@ -108,8 +108,8 @@ static int str_char (lua_State *L) { | |||
| 108 | luaL_Buffer b; | 108 | luaL_Buffer b; |
| 109 | luaL_buffinit(L, &b); | 109 | luaL_buffinit(L, &b); |
| 110 | for (i=1; i<=n; i++) { | 110 | for (i=1; i<=n; i++) { |
| 111 | int c = luaL_check_int(L, i); | 111 | int c = luaL_checkint(L, i); |
| 112 | luaL_arg_check(L, uchar(c) == c, i, "invalid value"); | 112 | luaL_argcheck(L, uchar(c) == c, i, "invalid value"); |
| 113 | luaL_putchar(&b, uchar(c)); | 113 | luaL_putchar(&b, uchar(c)); |
| 114 | } | 114 | } |
| 115 | luaL_pushresult(&b); | 115 | luaL_pushresult(&b); |
| @@ -439,7 +439,7 @@ static void push_onecapture (MatchState *ms, int i) { | |||
| 439 | 439 | ||
| 440 | static int push_captures (MatchState *ms, const char *s, const char *e) { | 440 | static int push_captures (MatchState *ms, const char *s, const char *e) { |
| 441 | int i; | 441 | int i; |
| 442 | luaL_check_stack(ms->L, ms->level, "too many captures"); | 442 | luaL_checkstack(ms->L, ms->level, "too many captures"); |
| 443 | if (ms->level == 0 && s) { /* no explicit captures? */ | 443 | if (ms->level == 0 && s) { /* no explicit captures? */ |
| 444 | lua_pushlstring(ms->L, s, e-s); /* return whole match */ | 444 | lua_pushlstring(ms->L, s, e-s); /* return whole match */ |
| 445 | return 1; | 445 | return 1; |
| @@ -454,10 +454,10 @@ static int push_captures (MatchState *ms, const char *s, const char *e) { | |||
| 454 | 454 | ||
| 455 | static int str_find (lua_State *L) { | 455 | static int str_find (lua_State *L) { |
| 456 | size_t l1, l2; | 456 | size_t l1, l2; |
| 457 | const char *s = luaL_check_lstr(L, 1, &l1); | 457 | const char *s = luaL_checklstring(L, 1, &l1); |
| 458 | const char *p = luaL_check_lstr(L, 2, &l2); | 458 | const char *p = luaL_checklstring(L, 2, &l2); |
| 459 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; | 459 | sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1; |
| 460 | luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range"); | 460 | luaL_argcheck(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range"); |
| 461 | if (lua_toboolean(L, 4) || /* explicit request? */ | 461 | if (lua_toboolean(L, 4) || /* explicit request? */ |
| 462 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ | 462 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
| 463 | /* do a plain search */ | 463 | /* do a plain search */ |
| @@ -517,8 +517,8 @@ static int gfind_aux (lua_State *L) { | |||
| 517 | 517 | ||
| 518 | 518 | ||
| 519 | static int gfind (lua_State *L) { | 519 | static int gfind (lua_State *L) { |
| 520 | luaL_check_string(L, 1); | 520 | luaL_checkstring(L, 1); |
| 521 | luaL_check_string(L, 2); | 521 | luaL_checkstring(L, 2); |
| 522 | lua_settop(L, 2); | 522 | lua_settop(L, 2); |
| 523 | lua_pushnumber(L, 0); | 523 | lua_pushnumber(L, 0); |
| 524 | lua_pushcclosure(L, gfind_aux, 3); | 524 | lua_pushcclosure(L, gfind_aux, 3); |
| @@ -563,14 +563,14 @@ static void add_s (MatchState *ms, luaL_Buffer *b, | |||
| 563 | 563 | ||
| 564 | static int str_gsub (lua_State *L) { | 564 | static int str_gsub (lua_State *L) { |
| 565 | size_t srcl; | 565 | size_t srcl; |
| 566 | const char *src = luaL_check_lstr(L, 1, &srcl); | 566 | const char *src = luaL_checklstring(L, 1, &srcl); |
| 567 | const char *p = luaL_check_string(L, 2); | 567 | const char *p = luaL_checkstring(L, 2); |
| 568 | int max_s = luaL_opt_int(L, 4, srcl+1); | 568 | int max_s = luaL_optint(L, 4, srcl+1); |
| 569 | int anchor = (*p == '^') ? (p++, 1) : 0; | 569 | int anchor = (*p == '^') ? (p++, 1) : 0; |
| 570 | int n = 0; | 570 | int n = 0; |
| 571 | MatchState ms; | 571 | MatchState ms; |
| 572 | luaL_Buffer b; | 572 | luaL_Buffer b; |
| 573 | luaL_arg_check(L, | 573 | luaL_argcheck(L, |
| 574 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), | 574 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), |
| 575 | 3, "string or function expected"); | 575 | 3, "string or function expected"); |
| 576 | luaL_buffinit(L, &b); | 576 | luaL_buffinit(L, &b); |
| @@ -609,7 +609,7 @@ static int str_gsub (lua_State *L) { | |||
| 609 | 609 | ||
| 610 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { | 610 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { |
| 611 | size_t l; | 611 | size_t l; |
| 612 | const char *s = luaL_check_lstr(L, arg, &l); | 612 | const char *s = luaL_checklstring(L, arg, &l); |
| 613 | luaL_putchar(b, '"'); | 613 | luaL_putchar(b, '"'); |
| 614 | while (l--) { | 614 | while (l--) { |
| 615 | switch (*s) { | 615 | switch (*s) { |
| @@ -659,7 +659,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, | |||
| 659 | static int str_format (lua_State *L) { | 659 | static int str_format (lua_State *L) { |
| 660 | int arg = 1; | 660 | int arg = 1; |
| 661 | size_t sfl; | 661 | size_t sfl; |
| 662 | const char *strfrmt = luaL_check_lstr(L, arg, &sfl); | 662 | const char *strfrmt = luaL_checklstring(L, arg, &sfl); |
| 663 | const char *strfrmt_end = strfrmt+sfl; | 663 | const char *strfrmt_end = strfrmt+sfl; |
| 664 | luaL_Buffer b; | 664 | luaL_Buffer b; |
| 665 | luaL_buffinit(L, &b); | 665 | luaL_buffinit(L, &b); |
| @@ -678,16 +678,16 @@ static int str_format (lua_State *L) { | |||
| 678 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 678 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
| 679 | switch (*strfrmt++) { | 679 | switch (*strfrmt++) { |
| 680 | case 'c': case 'd': case 'i': { | 680 | case 'c': case 'd': case 'i': { |
| 681 | sprintf(buff, form, luaL_check_int(L, arg)); | 681 | sprintf(buff, form, luaL_checkint(L, arg)); |
| 682 | break; | 682 | break; |
| 683 | } | 683 | } |
| 684 | case 'o': case 'u': case 'x': case 'X': { | 684 | case 'o': case 'u': case 'x': case 'X': { |
| 685 | sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg))); | 685 | sprintf(buff, form, (unsigned int)(luaL_checknumber(L, arg))); |
| 686 | break; | 686 | break; |
| 687 | } | 687 | } |
| 688 | case 'e': case 'E': case 'f': | 688 | case 'e': case 'E': case 'f': |
| 689 | case 'g': case 'G': { | 689 | case 'g': case 'G': { |
| 690 | sprintf(buff, form, luaL_check_number(L, arg)); | 690 | sprintf(buff, form, luaL_checknumber(L, arg)); |
| 691 | break; | 691 | break; |
| 692 | } | 692 | } |
| 693 | case 'q': { | 693 | case 'q': { |
| @@ -696,7 +696,7 @@ static int str_format (lua_State *L) { | |||
| 696 | } | 696 | } |
| 697 | case 's': { | 697 | case 's': { |
| 698 | size_t l; | 698 | size_t l; |
| 699 | const char *s = luaL_check_lstr(L, arg, &l); | 699 | const char *s = luaL_checklstring(L, arg, &l); |
| 700 | if (!hasprecision && l >= 100) { | 700 | if (!hasprecision && l >= 100) { |
| 701 | /* no precision and string is too long to be formatted; | 701 | /* no precision and string is too long to be formatted; |
| 702 | keep original string */ | 702 | keep original string */ |
| @@ -741,7 +741,7 @@ static const luaL_reg strlib[] = { | |||
| 741 | ** Open string library | 741 | ** Open string library |
| 742 | */ | 742 | */ |
| 743 | LUALIB_API int lua_strlibopen (lua_State *L) { | 743 | LUALIB_API int lua_strlibopen (lua_State *L) { |
| 744 | luaL_opennamedlib(L, LUA_STRLIBNAME, strlib, 0); | 744 | luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); |
| 745 | return 0; | 745 | return 0; |
| 746 | } | 746 | } |
| 747 | 747 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltablib.c,v 1.14 2002/10/23 19:08:23 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.15 2002/11/14 11:51:50 roberto Exp roberto $ |
| 3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -40,7 +40,7 @@ static void aux_setn (lua_State *L, int t, int n) { | |||
| 40 | 40 | ||
| 41 | static int aux_getn (lua_State *L, int t) { | 41 | static int aux_getn (lua_State *L, int t) { |
| 42 | int n; | 42 | int n; |
| 43 | luaL_check_type(L, t, LUA_TTABLE); | 43 | luaL_checktype(L, t, LUA_TTABLE); |
| 44 | lua_pushliteral(L, "n"); /* try t.n */ | 44 | lua_pushliteral(L, "n"); /* try t.n */ |
| 45 | lua_rawget(L, t); | 45 | lua_rawget(L, t); |
| 46 | if ((n = checkint(L)) >= 0) return n; | 46 | if ((n = checkint(L)) >= 0) return n; |
| @@ -64,7 +64,7 @@ static int aux_getn (lua_State *L, int t) { | |||
| 64 | static int luaB_foreachi (lua_State *L) { | 64 | static int luaB_foreachi (lua_State *L) { |
| 65 | int i; | 65 | int i; |
| 66 | int n = aux_getn(L, 1); | 66 | int n = aux_getn(L, 1); |
| 67 | luaL_check_type(L, 2, LUA_TFUNCTION); | 67 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 68 | for (i=1; i<=n; i++) { | 68 | for (i=1; i<=n; i++) { |
| 69 | lua_pushvalue(L, 2); /* function */ | 69 | lua_pushvalue(L, 2); /* function */ |
| 70 | lua_pushnumber(L, i); /* 1st argument */ | 70 | lua_pushnumber(L, i); /* 1st argument */ |
| @@ -79,8 +79,8 @@ static int luaB_foreachi (lua_State *L) { | |||
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | static int luaB_foreach (lua_State *L) { | 81 | static int luaB_foreach (lua_State *L) { |
| 82 | luaL_check_type(L, 1, LUA_TTABLE); | 82 | luaL_checktype(L, 1, LUA_TTABLE); |
| 83 | luaL_check_type(L, 2, LUA_TFUNCTION); | 83 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 84 | lua_pushnil(L); /* first key */ | 84 | lua_pushnil(L); /* first key */ |
| 85 | for (;;) { | 85 | for (;;) { |
| 86 | if (lua_next(L, 1) == 0) | 86 | if (lua_next(L, 1) == 0) |
| @@ -103,8 +103,8 @@ static int luaB_getn (lua_State *L) { | |||
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | static int luaB_setn (lua_State *L) { | 105 | static int luaB_setn (lua_State *L) { |
| 106 | luaL_check_type(L, 1, LUA_TTABLE); | 106 | luaL_checktype(L, 1, LUA_TTABLE); |
| 107 | aux_setn(L, 1, luaL_check_int(L, 2)); | 107 | aux_setn(L, 1, luaL_checkint(L, 2)); |
| 108 | return 0; | 108 | return 0; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| @@ -116,7 +116,7 @@ static int luaB_tinsert (lua_State *L) { | |||
| 116 | if (v == 2) /* called with only 2 arguments */ | 116 | if (v == 2) /* called with only 2 arguments */ |
| 117 | pos = n; /* insert new element at the end */ | 117 | pos = n; /* insert new element at the end */ |
| 118 | else { | 118 | else { |
| 119 | pos = luaL_check_int(L, 2); /* 2nd argument is the position */ | 119 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
| 120 | if (pos > n) n = pos; /* `grow' array if necessary */ | 120 | if (pos > n) n = pos; /* `grow' array if necessary */ |
| 121 | v = 3; /* function may be called with more than 3 args */ | 121 | v = 3; /* function may be called with more than 3 args */ |
| 122 | } | 122 | } |
| @@ -133,7 +133,7 @@ static int luaB_tinsert (lua_State *L) { | |||
| 133 | 133 | ||
| 134 | static int luaB_tremove (lua_State *L) { | 134 | static int luaB_tremove (lua_State *L) { |
| 135 | int n = aux_getn(L, 1); | 135 | int n = aux_getn(L, 1); |
| 136 | int pos = luaL_opt_int(L, 2, n); | 136 | int pos = luaL_optint(L, 2, n); |
| 137 | if (n <= 0) return 0; /* table is `empty' */ | 137 | if (n <= 0) return 0; /* table is `empty' */ |
| 138 | aux_setn(L, 1, n-1); /* t.n = n-1 */ | 138 | aux_setn(L, 1, n-1); /* t.n = n-1 */ |
| 139 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ | 139 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ |
| @@ -150,15 +150,15 @@ static int luaB_tremove (lua_State *L) { | |||
| 150 | static int str_concat (lua_State *L) { | 150 | static int str_concat (lua_State *L) { |
| 151 | luaL_Buffer b; | 151 | luaL_Buffer b; |
| 152 | size_t lsep; | 152 | size_t lsep; |
| 153 | const char *sep = luaL_opt_lstr(L, 2, "", &lsep); | 153 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
| 154 | int i = luaL_opt_int(L, 3, 1); | 154 | int i = luaL_optint(L, 3, 1); |
| 155 | int n = luaL_opt_int(L, 4, 0); | 155 | int n = luaL_optint(L, 4, 0); |
| 156 | luaL_check_type(L, 1, LUA_TTABLE); | 156 | luaL_checktype(L, 1, LUA_TTABLE); |
| 157 | if (n == 0) n = aux_getn(L, 1); | 157 | if (n == 0) n = aux_getn(L, 1); |
| 158 | luaL_buffinit(L, &b); | 158 | luaL_buffinit(L, &b); |
| 159 | for (; i <= n; i++) { | 159 | for (; i <= n; i++) { |
| 160 | lua_rawgeti(L, 1, i); | 160 | lua_rawgeti(L, 1, i); |
| 161 | luaL_arg_check(L, lua_isstring(L, -1), 1, "table contains non-strings"); | 161 | luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings"); |
| 162 | luaL_addvalue(&b); | 162 | luaL_addvalue(&b); |
| 163 | if (i != n) | 163 | if (i != n) |
| 164 | luaL_addlstring(&b, sep, lsep); | 164 | luaL_addlstring(&b, sep, lsep); |
| @@ -262,9 +262,9 @@ static void auxsort (lua_State *L, int l, int u) { | |||
| 262 | 262 | ||
| 263 | static int luaB_sort (lua_State *L) { | 263 | static int luaB_sort (lua_State *L) { |
| 264 | int n = aux_getn(L, 1); | 264 | int n = aux_getn(L, 1); |
| 265 | luaL_check_stack(L, 40, ""); /* assume array is smaller than 2^40 */ | 265 | luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ |
| 266 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 266 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
| 267 | luaL_check_type(L, 2, LUA_TFUNCTION); | 267 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 268 | lua_settop(L, 2); /* make sure there is two arguments */ | 268 | lua_settop(L, 2); /* make sure there is two arguments */ |
| 269 | auxsort(L, 1, n); | 269 | auxsort(L, 1, n); |
| 270 | return 0; | 270 | return 0; |
| @@ -293,7 +293,7 @@ LUALIB_API int lua_tablibopen (lua_State *L) { | |||
| 293 | lua_pushliteral(L, "__mode"); | 293 | lua_pushliteral(L, "__mode"); |
| 294 | lua_pushliteral(L, "k"); | 294 | lua_pushliteral(L, "k"); |
| 295 | lua_rawset(L, -3); /* metatable(N).__mode = "k" */ | 295 | lua_rawset(L, -3); /* metatable(N).__mode = "k" */ |
| 296 | luaL_opennamedlib(L, LUA_TABLIBNAME, tab_funcs, 1); | 296 | luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 1); |
| 297 | return 0; | 297 | return 0; |
| 298 | } | 298 | } |
| 299 | 299 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.141 2002/11/13 11:31:39 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.142 2002/11/14 11:51:23 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -178,7 +178,7 @@ void luaI_printcode (Proto *pt, int size) { | |||
| 178 | static int listcode (lua_State *L) { | 178 | static int listcode (lua_State *L) { |
| 179 | int pc; | 179 | int pc; |
| 180 | Proto *p; | 180 | Proto *p; |
| 181 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 181 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 182 | 1, "Lua function expected"); | 182 | 1, "Lua function expected"); |
| 183 | p = clvalue(index(L, 1))->l.p; | 183 | p = clvalue(index(L, 1))->l.p; |
| 184 | lua_newtable(L); | 184 | lua_newtable(L); |
| @@ -197,7 +197,7 @@ static int listcode (lua_State *L) { | |||
| 197 | static int listk (lua_State *L) { | 197 | static int listk (lua_State *L) { |
| 198 | Proto *p; | 198 | Proto *p; |
| 199 | int i; | 199 | int i; |
| 200 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 200 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 201 | 1, "Lua function expected"); | 201 | 1, "Lua function expected"); |
| 202 | p = clvalue(index(L, 1))->l.p; | 202 | p = clvalue(index(L, 1))->l.p; |
| 203 | lua_newtable(L); | 203 | lua_newtable(L); |
| @@ -212,10 +212,10 @@ static int listk (lua_State *L) { | |||
| 212 | 212 | ||
| 213 | static int listlocals (lua_State *L) { | 213 | static int listlocals (lua_State *L) { |
| 214 | Proto *p; | 214 | Proto *p; |
| 215 | int pc = luaL_check_int(L, 2) - 1; | 215 | int pc = luaL_checkint(L, 2) - 1; |
| 216 | int i = 0; | 216 | int i = 0; |
| 217 | const char *name; | 217 | const char *name; |
| 218 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 218 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 219 | 1, "Lua function expected"); | 219 | 1, "Lua function expected"); |
| 220 | p = clvalue(index(L, 1))->l.p; | 220 | p = clvalue(index(L, 1))->l.p; |
| 221 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 221 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
| @@ -248,7 +248,7 @@ static int mem_query (lua_State *L) { | |||
| 248 | return 3; | 248 | return 3; |
| 249 | } | 249 | } |
| 250 | else { | 250 | else { |
| 251 | memdebug_memlimit = luaL_check_int(L, 1); | 251 | memdebug_memlimit = luaL_checkint(L, 1); |
| 252 | return 0; | 252 | return 0; |
| 253 | } | 253 | } |
| 254 | } | 254 | } |
| @@ -256,13 +256,13 @@ static int mem_query (lua_State *L) { | |||
| 256 | 256 | ||
| 257 | static int hash_query (lua_State *L) { | 257 | static int hash_query (lua_State *L) { |
| 258 | if (lua_isnone(L, 2)) { | 258 | if (lua_isnone(L, 2)) { |
| 259 | luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); | 259 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
| 260 | lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); | 260 | lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); |
| 261 | } | 261 | } |
| 262 | else { | 262 | else { |
| 263 | TObject *o = index(L, 1); | 263 | TObject *o = index(L, 1); |
| 264 | Table *t; | 264 | Table *t; |
| 265 | luaL_check_type(L, 2, LUA_TTABLE); | 265 | luaL_checktype(L, 2, LUA_TTABLE); |
| 266 | t = hvalue(index(L, 2)); | 266 | t = hvalue(index(L, 2)); |
| 267 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); | 267 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); |
| 268 | } | 268 | } |
| @@ -283,8 +283,8 @@ static int stacklevel (lua_State *L) { | |||
| 283 | 283 | ||
| 284 | static int table_query (lua_State *L) { | 284 | static int table_query (lua_State *L) { |
| 285 | const Table *t; | 285 | const Table *t; |
| 286 | int i = luaL_opt_int(L, 2, -1); | 286 | int i = luaL_optint(L, 2, -1); |
| 287 | luaL_check_type(L, 1, LUA_TTABLE); | 287 | luaL_checktype(L, 1, LUA_TTABLE); |
| 288 | t = hvalue(index(L, 1)); | 288 | t = hvalue(index(L, 1)); |
| 289 | if (i == -1) { | 289 | if (i == -1) { |
| 290 | lua_pushnumber(L, t->sizearray); | 290 | lua_pushnumber(L, t->sizearray); |
| @@ -316,7 +316,7 @@ static int table_query (lua_State *L) { | |||
| 316 | 316 | ||
| 317 | static int string_query (lua_State *L) { | 317 | static int string_query (lua_State *L) { |
| 318 | stringtable *tb = &G(L)->strt; | 318 | stringtable *tb = &G(L)->strt; |
| 319 | int s = luaL_opt_int(L, 2, 0) - 1; | 319 | int s = luaL_optint(L, 2, 0) - 1; |
| 320 | if (s==-1) { | 320 | if (s==-1) { |
| 321 | lua_pushnumber(L ,tb->nuse); | 321 | lua_pushnumber(L ,tb->nuse); |
| 322 | lua_pushnumber(L ,tb->size); | 322 | lua_pushnumber(L ,tb->size); |
| @@ -338,8 +338,8 @@ static int string_query (lua_State *L) { | |||
| 338 | 338 | ||
| 339 | static int tref (lua_State *L) { | 339 | static int tref (lua_State *L) { |
| 340 | int level = lua_gettop(L); | 340 | int level = lua_gettop(L); |
| 341 | int lock = luaL_opt_int(L, 2, 1); | 341 | int lock = luaL_optint(L, 2, 1); |
| 342 | luaL_check_any(L, 1); | 342 | luaL_checkany(L, 1); |
| 343 | lua_pushvalue(L, 1); | 343 | lua_pushvalue(L, 1); |
| 344 | lua_pushnumber(L, lua_ref(L, lock)); | 344 | lua_pushnumber(L, lua_ref(L, lock)); |
| 345 | assert(lua_gettop(L) == level+1); /* +1 for result */ | 345 | assert(lua_gettop(L) == level+1); /* +1 for result */ |
| @@ -348,34 +348,34 @@ static int tref (lua_State *L) { | |||
| 348 | 348 | ||
| 349 | static int getref (lua_State *L) { | 349 | static int getref (lua_State *L) { |
| 350 | int level = lua_gettop(L); | 350 | int level = lua_gettop(L); |
| 351 | lua_getref(L, luaL_check_int(L, 1)); | 351 | lua_getref(L, luaL_checkint(L, 1)); |
| 352 | assert(lua_gettop(L) == level+1); | 352 | assert(lua_gettop(L) == level+1); |
| 353 | return 1; | 353 | return 1; |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | static int unref (lua_State *L) { | 356 | static int unref (lua_State *L) { |
| 357 | int level = lua_gettop(L); | 357 | int level = lua_gettop(L); |
| 358 | lua_unref(L, luaL_check_int(L, 1)); | 358 | lua_unref(L, luaL_checkint(L, 1)); |
| 359 | assert(lua_gettop(L) == level); | 359 | assert(lua_gettop(L) == level); |
| 360 | return 0; | 360 | return 0; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | static int metatable (lua_State *L) { | 363 | static int metatable (lua_State *L) { |
| 364 | luaL_check_any(L, 1); | 364 | luaL_checkany(L, 1); |
| 365 | if (lua_isnone(L, 2)) { | 365 | if (lua_isnone(L, 2)) { |
| 366 | if (lua_getmetatable(L, 1) == 0) | 366 | if (lua_getmetatable(L, 1) == 0) |
| 367 | lua_pushnil(L); | 367 | lua_pushnil(L); |
| 368 | } | 368 | } |
| 369 | else { | 369 | else { |
| 370 | lua_settop(L, 2); | 370 | lua_settop(L, 2); |
| 371 | luaL_check_type(L, 2, LUA_TTABLE); | 371 | luaL_checktype(L, 2, LUA_TTABLE); |
| 372 | lua_setmetatable(L, 1); | 372 | lua_setmetatable(L, 1); |
| 373 | } | 373 | } |
| 374 | return 1; | 374 | return 1; |
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | static int newuserdata (lua_State *L) { | 377 | static int newuserdata (lua_State *L) { |
| 378 | size_t size = luaL_check_int(L, 1); | 378 | size_t size = luaL_checkint(L, 1); |
| 379 | char *p = cast(char *, lua_newuserdata(L, size)); | 379 | char *p = cast(char *, lua_newuserdata(L, size)); |
| 380 | while (size--) *p++ = '\0'; | 380 | while (size--) *p++ = '\0'; |
| 381 | return 1; | 381 | return 1; |
| @@ -383,7 +383,7 @@ static int newuserdata (lua_State *L) { | |||
| 383 | 383 | ||
| 384 | 384 | ||
| 385 | static int pushuserdata (lua_State *L) { | 385 | static int pushuserdata (lua_State *L) { |
| 386 | lua_pushlightuserdata(L, cast(void *, luaL_check_int(L, 1))); | 386 | lua_pushlightuserdata(L, cast(void *, luaL_checkint(L, 1))); |
| 387 | return 1; | 387 | return 1; |
| 388 | } | 388 | } |
| 389 | 389 | ||
| @@ -397,7 +397,7 @@ static int udataval (lua_State *L) { | |||
| 397 | static int doonnewstack (lua_State *L) { | 397 | static int doonnewstack (lua_State *L) { |
| 398 | lua_State *L1 = lua_newthread(L); | 398 | lua_State *L1 = lua_newthread(L); |
| 399 | size_t l; | 399 | size_t l; |
| 400 | const char *s = luaL_check_lstr(L, 1, &l); | 400 | const char *s = luaL_checklstring(L, 1, &l); |
| 401 | int status = luaL_loadbuffer(L1, s, l, s); | 401 | int status = luaL_loadbuffer(L1, s, l, s); |
| 402 | if (status == 0) | 402 | if (status == 0) |
| 403 | status = lua_pcall(L1, 0, 0, 0); | 403 | status = lua_pcall(L1, 0, 0, 0); |
| @@ -407,12 +407,12 @@ static int doonnewstack (lua_State *L) { | |||
| 407 | 407 | ||
| 408 | 408 | ||
| 409 | static int s2d (lua_State *L) { | 409 | static int s2d (lua_State *L) { |
| 410 | lua_pushnumber(L, *cast(const double *, luaL_check_string(L, 1))); | 410 | lua_pushnumber(L, *cast(const double *, luaL_checkstring(L, 1))); |
| 411 | return 1; | 411 | return 1; |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | static int d2s (lua_State *L) { | 414 | static int d2s (lua_State *L) { |
| 415 | double d = luaL_check_number(L, 1); | 415 | double d = luaL_checknumber(L, 1); |
| 416 | lua_pushlstring(L, cast(char *, &d), sizeof(d)); | 416 | lua_pushlstring(L, cast(char *, &d), sizeof(d)); |
| 417 | return 1; | 417 | return 1; |
| 418 | } | 418 | } |
| @@ -430,7 +430,7 @@ static int newstate (lua_State *L) { | |||
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | static int loadlib (lua_State *L) { | 432 | static int loadlib (lua_State *L) { |
| 433 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); | 433 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); |
| 434 | lua_register(L1, "mathlibopen", lua_mathlibopen); | 434 | lua_register(L1, "mathlibopen", lua_mathlibopen); |
| 435 | lua_register(L1, "strlibopen", lua_strlibopen); | 435 | lua_register(L1, "strlibopen", lua_strlibopen); |
| 436 | lua_register(L1, "iolibopen", lua_iolibopen); | 436 | lua_register(L1, "iolibopen", lua_iolibopen); |
| @@ -440,16 +440,16 @@ static int loadlib (lua_State *L) { | |||
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | static int closestate (lua_State *L) { | 442 | static int closestate (lua_State *L) { |
| 443 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); | 443 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); |
| 444 | lua_close(L1); | 444 | lua_close(L1); |
| 445 | lua_unlock(L); /* close cannot unlock that */ | 445 | lua_unlock(L); /* close cannot unlock that */ |
| 446 | return 0; | 446 | return 0; |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | static int doremote (lua_State *L) { | 449 | static int doremote (lua_State *L) { |
| 450 | lua_State *L1 = cast(lua_State *,cast(unsigned long,luaL_check_number(L, 1))); | 450 | lua_State *L1 = cast(lua_State *,cast(unsigned long,luaL_checknumber(L, 1))); |
| 451 | size_t lcode; | 451 | size_t lcode; |
| 452 | const char *code = luaL_check_lstr(L, 2, &lcode); | 452 | const char *code = luaL_checklstring(L, 2, &lcode); |
| 453 | int status; | 453 | int status; |
| 454 | lua_settop(L1, 0); | 454 | lua_settop(L1, 0); |
| 455 | status = luaL_loadbuffer(L1, code, lcode, code); | 455 | status = luaL_loadbuffer(L1, code, lcode, code); |
| @@ -471,13 +471,13 @@ static int doremote (lua_State *L) { | |||
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | static int log2_aux (lua_State *L) { | 473 | static int log2_aux (lua_State *L) { |
| 474 | lua_pushnumber(L, luaO_log2(luaL_check_int(L, 1))); | 474 | lua_pushnumber(L, luaO_log2(luaL_checkint(L, 1))); |
| 475 | return 1; | 475 | return 1; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | 478 | ||
| 479 | static int test_do (lua_State *L) { | 479 | static int test_do (lua_State *L) { |
| 480 | const char *p = luaL_check_string(L, 1); | 480 | const char *p = luaL_checkstring(L, 1); |
| 481 | if (*p == '@') | 481 | if (*p == '@') |
| 482 | lua_dofile(L, p+1); | 482 | lua_dofile(L, p+1); |
| 483 | else | 483 | else |
| @@ -536,7 +536,7 @@ static const char *getname_aux (char *buff, const char **pc) { | |||
| 536 | 536 | ||
| 537 | static int testC (lua_State *L) { | 537 | static int testC (lua_State *L) { |
| 538 | char buff[30]; | 538 | char buff[30]; |
| 539 | const char *pc = luaL_check_string(L, 1); | 539 | const char *pc = luaL_checkstring(L, 1); |
| 540 | for (;;) { | 540 | for (;;) { |
| 541 | const char *inst = getname; | 541 | const char *inst = getname; |
| 542 | if EQ("") return 0; | 542 | if EQ("") return 0; |
| @@ -657,11 +657,11 @@ static int testC (lua_State *L) { | |||
| 657 | } | 657 | } |
| 658 | else if EQ("loadstring") { | 658 | else if EQ("loadstring") { |
| 659 | size_t sl; | 659 | size_t sl; |
| 660 | const char *s = luaL_check_lstr(L, getnum, &sl); | 660 | const char *s = luaL_checklstring(L, getnum, &sl); |
| 661 | luaL_loadbuffer(L, s, sl, s); | 661 | luaL_loadbuffer(L, s, sl, s); |
| 662 | } | 662 | } |
| 663 | else if EQ("loadfile") { | 663 | else if EQ("loadfile") { |
| 664 | luaL_loadfile(L, luaL_check_string(L, getnum)); | 664 | luaL_loadfile(L, luaL_checkstring(L, getnum)); |
| 665 | } | 665 | } |
| 666 | else if EQ("setmetatable") { | 666 | else if EQ("setmetatable") { |
| 667 | lua_setmetatable(L, getnum); | 667 | lua_setmetatable(L, getnum); |
| @@ -724,7 +724,7 @@ static void fim (void) { | |||
| 724 | int luaB_opentests (lua_State *L) { | 724 | int luaB_opentests (lua_State *L) { |
| 725 | lua_userstateopen(L); /* init lock */ | 725 | lua_userstateopen(L); /* init lock */ |
| 726 | lua_state = L; /* keep first state to be opened */ | 726 | lua_state = L; /* keep first state to be opened */ |
| 727 | luaL_opennamedlib(L, "T", tests_funcs, 0); | 727 | luaL_openlib(L, "T", tests_funcs, 0); |
| 728 | atexit(fim); | 728 | atexit(fim); |
| 729 | return 0; | 729 | return 0; |
| 730 | } | 730 | } |
