Browse Source

when possible, library functions accept nil as none

v5-2
Roberto Ierusalimschy 23 years ago
parent
commit
d1f220217b
  1. 6
      lauxlib.c
  2. 4
      lbaselib.c
  3. 4
      ldblib.c
  4. 9
      liolib.c
  5. 3
      lua.h

6
lauxlib.c

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.61 2002/03/07 18:15:10 roberto Exp roberto $
** $Id: lauxlib.c,v 1.62 2002/03/20 12:54:08 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -93,7 +93,7 @@ LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) {
if (lua_isnone(L, narg)) {
if (lua_isnoneornil(L, narg)) {
if (len)
*len = (def ? strlen(def) : 0);
return def;
@ -111,7 +111,7 @@ LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) {
LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) {
if (lua_isnone(L, narg)) return def;
if (lua_isnoneornil(L, narg)) return def;
else return luaL_check_number(L, narg);
}

4
lbaselib.c

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.60 2002/03/20 12:54:08 roberto Exp roberto $
** $Id: lbaselib.c,v 1.61 2002/03/27 12:49:53 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -620,7 +620,7 @@ static void set2 (lua_State *L, int i, int j) {
static int sort_comp (lua_State *L, int a, int b) {
/* WARNING: the caller (auxsort) must ensure stack space */
if (!lua_isnil(L, 2)) { /* function? */
if (!lua_isnoneornil(L, 2)) { /* function? */
int res;
lua_pushvalue(L, 2);
lua_pushvalue(L, a-1); /* -1 to compensate function */

4
ldblib.c

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.43 2002/02/07 17:24:32 roberto Exp roberto $
** $Id: ldblib.c,v 1.44 2002/03/20 12:54:08 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -141,7 +141,7 @@ static void linef (lua_State *L, lua_Debug *ar) {
static void sethook (lua_State *L, const char *key, lua_Hook hook,
lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) {
lua_settop(L, 1);
if (lua_isnil(L, 1))
if (lua_isnoneornil(L, 1))
(*sethookf)(L, NULL);
else if (lua_isfunction(L, 1))
(*sethookf)(L, hook);

9
liolib.c

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.131 2002/02/08 22:39:56 roberto Exp roberto $
** $Id: liolib.c,v 1.132 2002/03/20 12:54:08 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -406,7 +406,7 @@ static int io_seek (lua_State *L) {
static int io_flush (lua_State *L) {
FILE *f = (lua_isnone(L, 1)) ? (FILE *)(NULL) :
FILE *f = (lua_isnoneornil(L, 1)) ? (FILE *)(NULL) :
(FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
return pushresult(L, fflush(f) == 0);
}
@ -541,7 +541,7 @@ static int io_date (lua_State *L) {
static int io_time (lua_State *L) {
if (lua_isnone(L, 1)) /* called without args? */
if (lua_isnoneornil(L, 1)) /* called without args? */
lua_pushnumber(L, time(NULL)); /* return current time */
else {
time_t t;
@ -581,8 +581,7 @@ static int io_setloc (lua_State *L) {
"numeric", "time", NULL};
const char *l = lua_tostring(L, 1);
int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames);
luaL_arg_check(L, l || lua_isnil(L, 1) || lua_isnone(L, 1), 1,
"string expected");
luaL_arg_check(L, l || lua_isnoneornil(L, 1), 1, "string expected");
luaL_arg_check(L, op != -1, 2, "invalid option");
lua_pushstring(L, setlocale(cat[op], l));
return 1;

3
lua.h

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.123 2002/03/18 18:18:35 roberto Exp roberto $
** $Id: lua.h,v 1.124 2002/03/27 12:49:53 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: info@lua.org
@ -229,6 +229,7 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u);
#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN)
#define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L,n) <= 0)
#define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \
(sizeof(s)/sizeof(char))-1)

Loading…
Cancel
Save