diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-27 12:30:41 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-27 12:30:41 -0300 |
| commit | d1f220217beadc102a8d44b8e930a92a9f54b001 (patch) | |
| tree | 01e599fc7808818ad008599f192b57d32e97c995 | |
| parent | 405e3a4597d6f935a7ac224ce67dce660e69c7be (diff) | |
| download | lua-d1f220217beadc102a8d44b8e930a92a9f54b001.tar.gz lua-d1f220217beadc102a8d44b8e930a92a9f54b001.tar.bz2 lua-d1f220217beadc102a8d44b8e930a92a9f54b001.zip | |
when possible, library functions accept nil as none
| -rw-r--r-- | lauxlib.c | 6 | ||||
| -rw-r--r-- | lbaselib.c | 4 | ||||
| -rw-r--r-- | ldblib.c | 4 | ||||
| -rw-r--r-- | liolib.c | 9 | ||||
| -rw-r--r-- | lua.h | 3 |
5 files changed, 13 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.61 2002/03/07 18:15:10 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.62 2002/03/20 12:54:08 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,7 +93,7 @@ LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | |||
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { | 95 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { |
| 96 | if (lua_isnone(L, narg)) { | 96 | if (lua_isnoneornil(L, narg)) { |
| 97 | if (len) | 97 | if (len) |
| 98 | *len = (def ? strlen(def) : 0); | 98 | *len = (def ? strlen(def) : 0); |
| 99 | return def; | 99 | return def; |
| @@ -111,7 +111,7 @@ LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) { | |||
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) { | 113 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) { |
| 114 | if (lua_isnone(L, narg)) return def; | 114 | if (lua_isnoneornil(L, narg)) return def; |
| 115 | else return luaL_check_number(L, narg); | 115 | else return luaL_check_number(L, narg); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.60 2002/03/20 12:54:08 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.61 2002/03/27 12:49:53 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 | */ |
| @@ -620,7 +620,7 @@ static void set2 (lua_State *L, int i, int j) { | |||
| 620 | 620 | ||
| 621 | static int sort_comp (lua_State *L, int a, int b) { | 621 | static int sort_comp (lua_State *L, int a, int b) { |
| 622 | /* WARNING: the caller (auxsort) must ensure stack space */ | 622 | /* WARNING: the caller (auxsort) must ensure stack space */ |
| 623 | if (!lua_isnil(L, 2)) { /* function? */ | 623 | if (!lua_isnoneornil(L, 2)) { /* function? */ |
| 624 | int res; | 624 | int res; |
| 625 | lua_pushvalue(L, 2); | 625 | lua_pushvalue(L, 2); |
| 626 | lua_pushvalue(L, a-1); /* -1 to compensate function */ | 626 | lua_pushvalue(L, a-1); /* -1 to compensate function */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.43 2002/02/07 17:24:32 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.44 2002/03/20 12:54:08 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 | */ |
| @@ -141,7 +141,7 @@ static void linef (lua_State *L, lua_Debug *ar) { | |||
| 141 | static void sethook (lua_State *L, const char *key, lua_Hook hook, | 141 | static void sethook (lua_State *L, const char *key, lua_Hook hook, |
| 142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { | 142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { |
| 143 | lua_settop(L, 1); | 143 | lua_settop(L, 1); |
| 144 | if (lua_isnil(L, 1)) | 144 | if (lua_isnoneornil(L, 1)) |
| 145 | (*sethookf)(L, NULL); | 145 | (*sethookf)(L, NULL); |
| 146 | else if (lua_isfunction(L, 1)) | 146 | else if (lua_isfunction(L, 1)) |
| 147 | (*sethookf)(L, hook); | 147 | (*sethookf)(L, hook); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.131 2002/02/08 22:39:56 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.132 2002/03/20 12:54:08 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 | */ |
| @@ -406,7 +406,7 @@ static int io_seek (lua_State *L) { | |||
| 406 | 406 | ||
| 407 | 407 | ||
| 408 | static int io_flush (lua_State *L) { | 408 | static int io_flush (lua_State *L) { |
| 409 | FILE *f = (lua_isnone(L, 1)) ? (FILE *)(NULL) : | 409 | FILE *f = (lua_isnoneornil(L, 1)) ? (FILE *)(NULL) : |
| 410 | (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); | 410 | (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
| 411 | return pushresult(L, fflush(f) == 0); | 411 | return pushresult(L, fflush(f) == 0); |
| 412 | } | 412 | } |
| @@ -541,7 +541,7 @@ static int io_date (lua_State *L) { | |||
| 541 | 541 | ||
| 542 | 542 | ||
| 543 | static int io_time (lua_State *L) { | 543 | static int io_time (lua_State *L) { |
| 544 | if (lua_isnone(L, 1)) /* called without args? */ | 544 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 545 | lua_pushnumber(L, time(NULL)); /* return current time */ | 545 | lua_pushnumber(L, time(NULL)); /* return current time */ |
| 546 | else { | 546 | else { |
| 547 | time_t t; | 547 | time_t t; |
| @@ -581,8 +581,7 @@ static int io_setloc (lua_State *L) { | |||
| 581 | "numeric", "time", NULL}; | 581 | "numeric", "time", NULL}; |
| 582 | const char *l = lua_tostring(L, 1); | 582 | const char *l = lua_tostring(L, 1); |
| 583 | int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); | 583 | int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); |
| 584 | luaL_arg_check(L, l || lua_isnil(L, 1) || lua_isnone(L, 1), 1, | 584 | luaL_arg_check(L, l || lua_isnoneornil(L, 1), 1, "string expected"); |
| 585 | "string expected"); | ||
| 586 | luaL_arg_check(L, op != -1, 2, "invalid option"); | 585 | luaL_arg_check(L, op != -1, 2, "invalid option"); |
| 587 | lua_pushstring(L, setlocale(cat[op], l)); | 586 | lua_pushstring(L, setlocale(cat[op], l)); |
| 588 | return 1; | 587 | return 1; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.123 2002/03/18 18:18:35 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.124 2002/03/27 12:49:53 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -229,6 +229,7 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u); | |||
| 229 | #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) | 229 | #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) |
| 230 | #define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN) | 230 | #define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN) |
| 231 | #define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE) | 231 | #define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE) |
| 232 | #define lua_isnoneornil(L, n) (lua_type(L,n) <= 0) | ||
| 232 | 233 | ||
| 233 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ | 234 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ |
| 234 | (sizeof(s)/sizeof(char))-1) | 235 | (sizeof(s)/sizeof(char))-1) |
