aboutsummaryrefslogtreecommitdiffstats
path: root/lsircbot.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-06-14 11:28:03 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2013-06-14 11:28:03 +0000
commit1f5510af967b0a48d4c1e06ccb423f60838f4f7d (patch)
treec235468b21d7d6069487f971ad29c8eba3bb463c /lsircbot.c
parent2478b71738e7a8a54c5711302a6575bba87b3c7a (diff)
downloadsircbot-1f5510af967b0a48d4c1e06ccb423f60838f4f7d.tar.bz2
sircbot-1f5510af967b0a48d4c1e06ccb423f60838f4f7d.tar.xz
lua: add support for lua-5.2
Diffstat (limited to 'lsircbot.c')
-rw-r--r--lsircbot.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lsircbot.c b/lsircbot.c
index c283f0e..0b97d5a 100644
--- a/lsircbot.c
+++ b/lsircbot.c
@@ -15,13 +15,22 @@
#define VERSION "unknown"
#endif
+#if LUA_VERSION_NUM < 502
+# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
+# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
+#endif
+
static int *Lsbconn_checkarg(lua_State *L, int index)
{
int *fdp;
luaL_checktype(L, index, LUA_TUSERDATA);
fdp = (int *) luaL_checkudata(L, index, SBCONN_META);
- if (fdp == NULL)
- luaL_typerror(L, index, SBCONN_META);
+ if (fdp == NULL) {
+ const char *msg = lua_pushfstring(L, "%s expected, got %s",
+ SBCONN_META,
+ luaL_typename(L, index));
+ luaL_argerror(L, index, msg);
+ }
return fdp;
}
@@ -67,12 +76,12 @@ static int Lsbconn_send(lua_State *L)
return 1;
}
-static const luaL_reg sbconn_meta_methods[] = {
+static const luaL_Reg sbconn_meta_methods[] = {
{ "__gc", Lsbconn_destroy },
{ NULL, NULL }
};
-static const luaL_reg sircbot_methods[] = {
+static const luaL_Reg sircbot_methods[] = {
{ "connect", Lsbconn_new },
{ "send", Lsbconn_send },
{ NULL, NULL }
@@ -81,7 +90,7 @@ static const luaL_reg sircbot_methods[] = {
LUALIB_API int luaopen_sircbot(lua_State *L)
{
/* register sircbot library */
- luaL_register(L, "sircbot", sircbot_methods);
+ luaL_newlib(L, sircbot_methods);
/* version */
lua_pushliteral(L, "version");
@@ -90,7 +99,7 @@ LUALIB_API int luaopen_sircbot(lua_State *L)
/* register metatable for it */
luaL_newmetatable(L, SBCONN_META);
- luaL_register(L, NULL, sbconn_meta_methods);
+ luaL_setfuncs(L, sbconn_meta_methods, 0);
lua_pushliteral(L, "__index");
lua_pushvalue(L, -3);
lua_rawset(L, -3);