From fa2f1ec7bae81d43e6edd1b29ecd610e24ebb301 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 4 Oct 2002 11:31:40 -0300 Subject: to avoid `strerror', define itself to something else; nil has a special, fixed reference --- lauxlib.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index 3f863602..3f34db03 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,20 +1,16 @@ /* -** $Id: lauxlib.c,v 1.85 2002/09/05 19:45:42 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.86 2002/09/16 19:49:45 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ #include +#include #include #include #include -#ifndef lua_filerror -#include -#define lua_fileerror (strerror(errno)) -#endif - /* This file uses only the official API of Lua. ** Any function declared here could be written as an application function. @@ -292,6 +288,10 @@ LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { LUALIB_API int luaL_ref (lua_State *L, int t) { int ref; + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } lua_rawgeti(L, t, 0); /* get first free element */ ref = (int)lua_tonumber(L, -1); /* ref = t[0] */ lua_pop(L, 1); /* remove it from stack */ @@ -347,7 +347,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { static int errfile (lua_State *L, const char *filename) { if (filename == NULL) filename = "stdin"; - lua_pushfstring(L, "cannot read %s: %s", filename, lua_fileerror); + lua_pushfstring(L, "cannot read %s: %s", filename, strerror(errno)); return LUA_ERRFILE; } -- cgit v1.2.3-55-g6feb