From b3c4f46179ed5b27ca76a824f8730fa50dbaae0b Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 16 Apr 2012 20:41:48 +0800 Subject: merged lua_typerrror.{c,h} into auxiliar.{c,h} --- src/auxiliar.c | 14 ++++++++++++-- src/auxiliar.h | 1 + src/lua_typeerror.c | 10 ---------- src/lua_typeerror.h | 7 ------- src/makefile | 14 ++++++-------- src/options.c | 5 ++--- 6 files changed, 21 insertions(+), 30 deletions(-) delete mode 100644 src/lua_typeerror.c delete mode 100644 src/lua_typeerror.h (limited to 'src') diff --git a/src/auxiliar.c b/src/auxiliar.c index 3396fc1..c4e5260 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -8,7 +8,6 @@ #include #include "auxiliar.h" -#include "lua_typeerror.h" /*=========================================================================*\ * Exported functions @@ -82,7 +81,7 @@ void auxiliar_add2group(lua_State *L, const char *classname, const char *groupna \*-------------------------------------------------------------------------*/ int auxiliar_checkboolean(lua_State *L, int objidx) { if (!lua_isboolean(L, objidx)) - luaL_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); + auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); return lua_toboolean(L, objidx); } @@ -148,3 +147,14 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { return luaL_checkudata(L, objidx, classname); } + +/*-------------------------------------------------------------------------*\ +* Throws error when argument does not have correct type. +* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2. +\*-------------------------------------------------------------------------*/ +int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, + luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + diff --git a/src/auxiliar.h b/src/auxiliar.h index c53b39e..ea99013 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -42,5 +42,6 @@ void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); int auxiliar_checkboolean(lua_State *L, int objidx); int auxiliar_tostring(lua_State *L); +int auxiliar_typeerror(lua_State *L, int narg, const char *tname); #endif /* AUXILIAR_H */ diff --git a/src/lua_typeerror.c b/src/lua_typeerror.c deleted file mode 100644 index d6a3d76..0000000 --- a/src/lua_typeerror.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "lua_typeerror.h" -#include "lua.h" -#include "lauxlib.h" - -int luaL_typeerror (lua_State *L, int narg, const char *tname) -{ - const char *msg = lua_pushfstring(L, "%s expected, got %s",tname, luaL_typename(L, narg)); - return luaL_argerror(L, narg, msg); -} - diff --git a/src/lua_typeerror.h b/src/lua_typeerror.h deleted file mode 100644 index 4f2aafd..0000000 --- a/src/lua_typeerror.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef LUA_TYPEERROR_H_ -#define LUA_TYPEERROR_H_ - -struct lua_State; -int luaL_typeerror (struct lua_State *L, int narg, const char *tname); - -#endif diff --git a/src/makefile b/src/makefile index a38ff98..0665c14 100644 --- a/src/makefile +++ b/src/makefile @@ -1,10 +1,11 @@ PLAT?=macosx LUAV?=5.1 -prefix=/usr/local +prefix=../../../build/lua/$(LUAV) +#prefix=/usr/local #prefix=/opt/local #prefix=. -LUAINC_macosx=/usr/local/include +LUAINC_macosx=../../../build/lua/$(LUAV)/include #LUAINC_macosx=/opt/local/include #LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.2.0-beta/src #LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.1.4/src @@ -131,8 +132,7 @@ SOCKET_OBJS= \ except.$(O) \ select.$(O) \ tcp.$(O) \ - udp.$(O) \ - lua_typeerror.$(O) + udp.$(O) #------ # Modules belonging mime-core @@ -150,8 +150,7 @@ UNIX_OBJS=\ timeout.$(O) \ io.$(O) \ usocket.$(O) \ - unix.$(O) \ - lua_typeerror.$(O) + unix.$(O) #------ # Modules belonging to serial (device streams) @@ -163,8 +162,7 @@ SERIAL_OBJS:=\ timeout.$(O) \ io.$(O) \ usocket.$(O) \ - serial.$(O) \ - lua_typeerror.$(O) + serial.$(O) #------ # Files to install diff --git a/src/options.c b/src/options.c index ab9e621..c122ead 100644 --- a/src/options.c +++ b/src/options.c @@ -11,7 +11,6 @@ #include "auxiliar.h" #include "options.h" #include "inet.h" -#include "lua_typeerror.h" /*=========================================================================*\ * Internal functions prototypes @@ -122,7 +121,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) int opt_set_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name, table */ - if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE)); + if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE)); lua_pushstring(L, "on"); lua_gettable(L, 3); if (!lua_isboolean(L, -1)) @@ -203,7 +202,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps) static int opt_setmembership(lua_State *L, p_socket ps, int level, int name) { struct ip_mreq val; /* obj, name, table */ - if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE)); + if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE)); lua_pushstring(L, "multiaddr"); lua_gettable(L, 3); if (!lua_isstring(L, -1)) -- cgit v1.2.3-55-g6feb