merged lua_typerrror.{c,h} into auxiliar.{c,h}

This commit is contained in:
Diego Nehab 2012-04-16 20:41:48 +08:00
parent 4b671f4551
commit b3c4f46179
7 changed files with 58 additions and 30 deletions

View file

@ -8,7 +8,6 @@
#include <stdio.h>
#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);
}

View file

@ -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 */

View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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))