aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2012-04-16 20:41:48 +0800
committerDiego Nehab <diego.nehab@gmail.com>2012-04-16 20:41:48 +0800
commitb3c4f46179ed5b27ca76a824f8730fa50dbaae0b (patch)
treeb5056d95f3307c49d942262387bba2ec3c949451 /src
parent4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc (diff)
downloadluasocket-b3c4f46179ed5b27ca76a824f8730fa50dbaae0b.tar.gz
luasocket-b3c4f46179ed5b27ca76a824f8730fa50dbaae0b.tar.bz2
luasocket-b3c4f46179ed5b27ca76a824f8730fa50dbaae0b.zip
merged lua_typerrror.{c,h} into auxiliar.{c,h}
Diffstat (limited to 'src')
-rw-r--r--src/auxiliar.c14
-rw-r--r--src/auxiliar.h1
-rw-r--r--src/lua_typeerror.c10
-rw-r--r--src/lua_typeerror.h7
-rw-r--r--src/makefile14
-rw-r--r--src/options.c5
6 files changed, 21 insertions, 30 deletions
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 @@
8#include <stdio.h> 8#include <stdio.h>
9 9
10#include "auxiliar.h" 10#include "auxiliar.h"
11#include "lua_typeerror.h"
12 11
13/*=========================================================================*\ 12/*=========================================================================*\
14* Exported functions 13* Exported functions
@@ -82,7 +81,7 @@ void auxiliar_add2group(lua_State *L, const char *classname, const char *groupna
82\*-------------------------------------------------------------------------*/ 81\*-------------------------------------------------------------------------*/
83int auxiliar_checkboolean(lua_State *L, int objidx) { 82int auxiliar_checkboolean(lua_State *L, int objidx) {
84 if (!lua_isboolean(L, objidx)) 83 if (!lua_isboolean(L, objidx))
85 luaL_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); 84 auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));
86 return lua_toboolean(L, objidx); 85 return lua_toboolean(L, objidx);
87} 86}
88 87
@@ -148,3 +147,14 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
148void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { 147void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
149 return luaL_checkudata(L, objidx, classname); 148 return luaL_checkudata(L, objidx, classname);
150} 149}
150
151/*-------------------------------------------------------------------------*\
152* Throws error when argument does not have correct type.
153* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2.
154\*-------------------------------------------------------------------------*/
155int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
156 const char *msg = lua_pushfstring(L, "%s expected, got %s", tname,
157 luaL_typename(L, narg));
158 return luaL_argerror(L, narg, msg);
159}
160
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);
42void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); 42void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx);
43int auxiliar_checkboolean(lua_State *L, int objidx); 43int auxiliar_checkboolean(lua_State *L, int objidx);
44int auxiliar_tostring(lua_State *L); 44int auxiliar_tostring(lua_State *L);
45int auxiliar_typeerror(lua_State *L, int narg, const char *tname);
45 46
46#endif /* AUXILIAR_H */ 47#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 @@
1#include "lua_typeerror.h"
2#include "lua.h"
3#include "lauxlib.h"
4
5int luaL_typeerror (lua_State *L, int narg, const char *tname)
6{
7 const char *msg = lua_pushfstring(L, "%s expected, got %s",tname, luaL_typename(L, narg));
8 return luaL_argerror(L, narg, msg);
9}
10
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 @@
1#ifndef LUA_TYPEERROR_H_
2#define LUA_TYPEERROR_H_
3
4struct lua_State;
5int luaL_typeerror (struct lua_State *L, int narg, const char *tname);
6
7#endif
diff --git a/src/makefile b/src/makefile
index a38ff98..0665c14 100644
--- a/src/makefile
+++ b/src/makefile
@@ -1,10 +1,11 @@
1PLAT?=macosx 1PLAT?=macosx
2LUAV?=5.1 2LUAV?=5.1
3prefix=/usr/local 3prefix=../../../build/lua/$(LUAV)
4#prefix=/usr/local
4#prefix=/opt/local 5#prefix=/opt/local
5#prefix=. 6#prefix=.
6 7
7LUAINC_macosx=/usr/local/include 8LUAINC_macosx=../../../build/lua/$(LUAV)/include
8#LUAINC_macosx=/opt/local/include 9#LUAINC_macosx=/opt/local/include
9#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.2.0-beta/src 10#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.2.0-beta/src
10#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.1.4/src 11#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.1.4/src
@@ -131,8 +132,7 @@ SOCKET_OBJS= \
131 except.$(O) \ 132 except.$(O) \
132 select.$(O) \ 133 select.$(O) \
133 tcp.$(O) \ 134 tcp.$(O) \
134 udp.$(O) \ 135 udp.$(O)
135 lua_typeerror.$(O)
136 136
137#------ 137#------
138# Modules belonging mime-core 138# Modules belonging mime-core
@@ -150,8 +150,7 @@ UNIX_OBJS=\
150 timeout.$(O) \ 150 timeout.$(O) \
151 io.$(O) \ 151 io.$(O) \
152 usocket.$(O) \ 152 usocket.$(O) \
153 unix.$(O) \ 153 unix.$(O)
154 lua_typeerror.$(O)
155 154
156#------ 155#------
157# Modules belonging to serial (device streams) 156# Modules belonging to serial (device streams)
@@ -163,8 +162,7 @@ SERIAL_OBJS:=\
163 timeout.$(O) \ 162 timeout.$(O) \
164 io.$(O) \ 163 io.$(O) \
165 usocket.$(O) \ 164 usocket.$(O) \
166 serial.$(O) \ 165 serial.$(O)
167 lua_typeerror.$(O)
168 166
169#------ 167#------
170# Files to install 168# 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 @@
11#include "auxiliar.h" 11#include "auxiliar.h"
12#include "options.h" 12#include "options.h"
13#include "inet.h" 13#include "inet.h"
14#include "lua_typeerror.h"
15 14
16/*=========================================================================*\ 15/*=========================================================================*\
17* Internal functions prototypes 16* Internal functions prototypes
@@ -122,7 +121,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
122int opt_set_linger(lua_State *L, p_socket ps) 121int opt_set_linger(lua_State *L, p_socket ps)
123{ 122{
124 struct linger li; /* obj, name, table */ 123 struct linger li; /* obj, name, table */
125 if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE)); 124 if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));
126 lua_pushstring(L, "on"); 125 lua_pushstring(L, "on");
127 lua_gettable(L, 3); 126 lua_gettable(L, 3);
128 if (!lua_isboolean(L, -1)) 127 if (!lua_isboolean(L, -1))
@@ -203,7 +202,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
203static int opt_setmembership(lua_State *L, p_socket ps, int level, int name) 202static int opt_setmembership(lua_State *L, p_socket ps, int level, int name)
204{ 203{
205 struct ip_mreq val; /* obj, name, table */ 204 struct ip_mreq val; /* obj, name, table */
206 if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE)); 205 if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));
207 lua_pushstring(L, "multiaddr"); 206 lua_pushstring(L, "multiaddr");
208 lua_gettable(L, 3); 207 lua_gettable(L, 3);
209 if (!lua_isstring(L, -1)) 208 if (!lua_isstring(L, -1))