summaryrefslogtreecommitdiff
path: root/src/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lauxlib.c')
-rw-r--r--src/lauxlib.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/lauxlib.c b/src/lauxlib.c
index abf589ae..0a6cea0a 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.267 2014/07/19 14:37:09 roberto Exp $
+** $Id: lauxlib.c,v 1.270 2014/10/22 11:44:20 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -82,12 +82,12 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
static void pushfuncname (lua_State *L, lua_Debug *ar) {
if (*ar->namewhat != '\0') /* is there a name? */
- lua_pushfstring(L, "function " LUA_QS, ar->name);
+ lua_pushfstring(L, "function '%s'", ar->name);
else if (*ar->what == 'm') /* main? */
lua_pushliteral(L, "main chunk");
else if (*ar->what == 'C') {
if (pushglobalfuncname(L, ar)) {
- lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
+ lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
lua_remove(L, -2); /* remove name */
}
else
@@ -158,25 +158,25 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {
if (strcmp(ar.namewhat, "method") == 0) {
arg--; /* do not count `self' */
if (arg == 0) /* error is in the self argument itself? */
- return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
+ return luaL_error(L, "calling '%s' on bad self (%s)",
ar.name, extramsg);
}
if (ar.name == NULL)
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
- return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
+ return luaL_error(L, "bad argument #%d to '%s' (%s)",
arg, ar.name, extramsg);
}
static int typeerror (lua_State *L, int arg, const char *tname) {
const char *msg;
- const char *typearg = luaL_typename(L, arg);
- if (lua_getmetatable(L, arg)) {
- if (lua_getfield(L, -1, "__name") == LUA_TSTRING)
- typearg = lua_tostring(L, -1);
- }
+ const char *typearg; /* name for the type of the actual argument */
+ if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING)
+ typearg = lua_tostring(L, -1); /* use the given type name */
else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)
- typearg = "light userdata";
+ typearg = "light userdata"; /* special name for messages */
+ else
+ typearg = luaL_typename(L, arg); /* standard name */
msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
return luaL_argerror(L, arg, msg);
}
@@ -229,7 +229,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
}
-#if !defined(inspectstat) /* { */
+#if !defined(l_inspectstat) /* { */
#if defined(LUA_USE_POSIX)
@@ -238,13 +238,13 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
/*
** use appropriate macros to interpret 'pclose' return status
*/
-#define inspectstat(stat,what) \
+#define l_inspectstat(stat,what) \
if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
#else
-#define inspectstat(stat,what) /* no op */
+#define l_inspectstat(stat,what) /* no op */
#endif
@@ -256,7 +256,7 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) {
if (stat == -1) /* error? */
return luaL_fileresult(L, 0, NULL);
else {
- inspectstat(stat, what); /* interpret result */
+ l_inspectstat(stat, what); /* interpret result */
if (*what == 'e' && stat == 0) /* successful termination? */
lua_pushboolean(L, 1);
else
@@ -335,7 +335,7 @@ LUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,
if (strcmp(lst[i], name) == 0)
return i;
return luaL_argerror(L, arg,
- lua_pushfstring(L, "invalid option " LUA_QS, name));
+ lua_pushfstring(L, "invalid option '%s'", name));
}
@@ -701,22 +701,23 @@ LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
if (!lua_getmetatable(L, obj)) /* no metatable? */
- return 0;
- lua_pushstring(L, event);
- if (lua_rawget(L, -2) == LUA_TNIL) { /* is metafield nil? */
- lua_pop(L, 2); /* remove metatable and metafield */
- return 0;
- }
+ return LUA_TNIL;
else {
- lua_remove(L, -2); /* remove only metatable */
- return 1;
+ int tt;
+ lua_pushstring(L, event);
+ tt = lua_rawget(L, -2);
+ if (tt == LUA_TNIL) /* is metafield nil? */
+ lua_pop(L, 2); /* remove metatable and metafield */
+ else
+ lua_remove(L, -2); /* remove only metatable */
+ return tt; /* return metafield type */
}
}
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
obj = lua_absindex(L, obj);
- if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
+ if (luaL_getmetafield(L, obj, event) == LUA_TNIL) /* no metafield? */
return 0;
lua_pushvalue(L, obj);
lua_call(L, 1, 1);
@@ -822,7 +823,7 @@ LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
/* try global variable (and create one if it does not exist) */
lua_pushglobaltable(L);
if (luaL_findtable(L, 0, modname, sizehint) != NULL)
- luaL_error(L, "name conflict for module " LUA_QS, modname);
+ luaL_error(L, "name conflict for module '%s'", modname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
}