diff options
| -rw-r--r-- | lauxlib.c | 13 | ||||
| -rw-r--r-- | lauxlib.h | 5 | ||||
| -rw-r--r-- | lbaselib.c | 5 | ||||
| -rw-r--r-- | liolib.c | 8 | ||||
| -rw-r--r-- | loslib.c | 5 |
5 files changed, 18 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.132 2005/05/16 21:19:00 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.133 2005/05/17 19:49:15 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 | */ |
| @@ -95,12 +95,15 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { | |||
| 95 | /* }====================================================== */ | 95 | /* }====================================================== */ |
| 96 | 96 | ||
| 97 | 97 | ||
| 98 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | 98 | LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, |
| 99 | const char *const lst[]) { | ||
| 100 | const char *name = (def) ? luaL_optstring(L, narg, def) : | ||
| 101 | luaL_checkstring(L, narg); | ||
| 99 | int i; | 102 | int i; |
| 100 | for (i=0; list[i]; i++) | 103 | for (i=0; lst[i]; i++) |
| 101 | if (strcmp(list[i], name) == 0) | 104 | if (strcmp(lst[i], name) == 0) |
| 102 | return i; | 105 | return i; |
| 103 | return -1; /* name not found */ | 106 | return luaL_error(L, "invalid option " LUA_QS, name); |
| 104 | } | 107 | } |
| 105 | 108 | ||
| 106 | 109 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.75 2005/03/29 16:20:48 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.76 2005/05/20 19:09:05 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 | */ |
| @@ -59,7 +59,8 @@ LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); | |||
| 59 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); | 59 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); |
| 60 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); | 60 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); |
| 61 | 61 | ||
| 62 | LUALIB_API int (luaL_findstring) (const char *st, const char *const lst[]); | 62 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, |
| 63 | const char *const lst[]); | ||
| 63 | 64 | ||
| 64 | LUALIB_API const char *(luaL_searchpath) (lua_State *L, const char *name, | 65 | LUALIB_API const char *(luaL_searchpath) (lua_State *L, const char *name, |
| 65 | const char *path); | 66 | const char *path); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.176 2005/05/17 19:49:15 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.177 2005/05/20 15:53:42 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 | */ |
| @@ -192,9 +192,8 @@ static int luaB_collectgarbage (lua_State *L) { | |||
| 192 | "count", "step", "setpause", "setstepmul", NULL}; | 192 | "count", "step", "setpause", "setstepmul", NULL}; |
| 193 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, | 193 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, |
| 194 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; | 194 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; |
| 195 | int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); | 195 | int o = luaL_checkoption(L, 1, "collect", opts); |
| 196 | int ex = luaL_optinteger(L, 2, 0); | 196 | int ex = luaL_optinteger(L, 2, 0); |
| 197 | luaL_argcheck(L, o >= 0, 1, "invalid option"); | ||
| 198 | lua_pushinteger(L, lua_gc(L, optsnum[o], ex)); | 197 | lua_pushinteger(L, lua_gc(L, optsnum[o], ex)); |
| 199 | return 1; | 198 | return 1; |
| 200 | } | 199 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.59 2005/03/18 18:01:14 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.60 2005/05/16 21:19:00 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 | */ |
| @@ -400,9 +400,8 @@ static int f_seek (lua_State *L) { | |||
| 400 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 400 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
| 401 | static const char *const modenames[] = {"set", "cur", "end", NULL}; | 401 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 402 | FILE *f = tofile(L); | 402 | FILE *f = tofile(L); |
| 403 | int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames); | 403 | int op = luaL_checkoption(L, 2, "cur", modenames); |
| 404 | lua_Integer offset = luaL_optinteger(L, 3, 0); | 404 | lua_Integer offset = luaL_optinteger(L, 3, 0); |
| 405 | luaL_argcheck(L, op != -1, 2, "invalid mode"); | ||
| 406 | op = fseek(f, offset, mode[op]); | 405 | op = fseek(f, offset, mode[op]); |
| 407 | if (op) | 406 | if (op) |
| 408 | return pushresult(L, 0, NULL); /* error */ | 407 | return pushresult(L, 0, NULL); /* error */ |
| @@ -417,8 +416,7 @@ static int f_setvbuf (lua_State *L) { | |||
| 417 | static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; | 416 | static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; |
| 418 | static const char *const modenames[] = {"no", "full", "line", NULL}; | 417 | static const char *const modenames[] = {"no", "full", "line", NULL}; |
| 419 | FILE *f = tofile(L); | 418 | FILE *f = tofile(L); |
| 420 | int op = luaL_findstring(luaL_checkstring(L, 2), modenames); | 419 | int op = luaL_checkoption(L, 2, NULL, modenames); |
| 421 | luaL_argcheck(L, op != -1, 2, "invalid mode"); | ||
| 422 | return pushresult(L, setvbuf(f, NULL, mode[op], 0) == 0, NULL); | 420 | return pushresult(L, setvbuf(f, NULL, mode[op], 0) == 0, NULL); |
| 423 | } | 421 | } |
| 424 | 422 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loslib.c,v 1.8 2005/05/16 21:19:00 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.9 2005/05/17 19:49:15 roberto Exp roberto $ |
| 3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -197,9 +197,8 @@ static int io_setloc (lua_State *L) { | |||
| 197 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 197 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| 198 | "numeric", "time", NULL}; | 198 | "numeric", "time", NULL}; |
| 199 | const char *l = lua_tostring(L, 1); | 199 | const char *l = lua_tostring(L, 1); |
| 200 | int op = luaL_findstring(luaL_optstring(L, 2, "all"), catnames); | 200 | int op = luaL_checkoption(L, 2, "all", catnames); |
| 201 | luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); | 201 | luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); |
| 202 | luaL_argcheck(L, op != -1, 2, "invalid option"); | ||
| 203 | lua_pushstring(L, setlocale(cat[op], l)); | 202 | lua_pushstring(L, setlocale(cat[op], l)); |
| 204 | return 1; | 203 | return 1; |
| 205 | } | 204 | } |
