aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);