summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-05-10 00:42:47 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-05-10 00:42:47 +0200
commit36b0b18ccd0a14a1cd24c5452f62f0ca5c5f557c (patch)
tree3e3b19ce33be7c6cc108a6797bebd0581f856b08
parentfixed typo (diff)
added inital support for Lua 5.2
-rwxr-xr-xsrc/configure35
-rw-r--r--src/gcsd.c25
-rw-r--r--src/l_log.c9
-rw-r--r--src/l_rawio.c9
-rw-r--r--src/l_sig_handler.c9
-rw-r--r--src/l_tcp.c9
-rw-r--r--src/l_timer.c11
-rw-r--r--src/l_util.c18
8 files changed, 109 insertions, 16 deletions
diff --git a/src/configure b/src/configure
index fe013b1..ac27ca6 100755
--- a/src/configure
+++ b/src/configure
@@ -39,6 +39,7 @@ USE_CLANG=0
LUA_DIR=''
LUA=''
LUAC=''
+LUA_VER=''
PREFIX='/usr/local'
BINDIR=''
@@ -61,6 +62,7 @@ print_usage() {
echo " --examplesdir=<DIR> the path to the examples files (default: $PREFIX/share/examples)"
echo " --no-examples dont't install example files"
echo " --with-lua=<DIR> use this lua tree instead of system default"
+ echo " --lua-version=nnn set fixed Lua version for automatic detection (501 -> 5.1, 502 -> 5.2)"
echo " --use-clang use clang/llvm as compiler/linker"
}
@@ -100,6 +102,9 @@ do
--with-lua=*)
LUA_DIR=${arg#--with-lua=}
;;
+ --lua-version=*)
+ LUA_VER=${arg#--lua-version=}
+ ;;
--ebuild-compat)
EBUILD_COMPAT=1
;;
@@ -161,14 +166,32 @@ esac
test_lua_version()
{
- LUA_VERSION=`cat $1 | grep "#define LUA_VERSION[ ]" | cut -f2- | tr -d '"' | sed -e 's/Lua \([0-9][0-9.]*\)/\1/'`
+ LUA_VERSION_MAJ=`cat $1 | grep "#define LUA_VERSION_MAJOR[ ]" | cut -f2- | tr -d '"'`
+ LUA_VERSION_MIN=`cat $1 | grep "#define LUA_VERSION_MINOR[ ]" | cut -f2- | tr -d '"'`
+ LUA_VERSION_REL=`cat $1 | grep "#define LUA_VERSION_RELEASE[ ]" | cut -f2- | tr -d '"'`
+
+ LUA_VERSION="$LUA_VERSION_MAJ.$LUA_VERSION_MIN"
+ LUA_RELEASE="$LUA_VERSION_MAJ.$LUA_VERSION_MIN.$LUA_VERSION_REL"
+
+ if [ -z "$LUA_VERSION_MAJ" ]; then
+ LUA_VERSION=`cat $1 | grep "#define LUA_VERSION[ ]" | cut -f2- | tr -d '"' | sed -e 's/Lua \([0-9][0-9.]*\)/\1/'`
+ LUA_RELEASE=`cat $1 | grep "#define LUA_RELEASE[ ]" | cut -f2- | tr -d '"' | sed -e 's/Lua //'`
+ fi
+
LUA_VERSION_NUM=`cat $1 | grep "#define LUA_VERSION_NUM" | awk '{ print $3 }'`
- LUA_RELEASE=`cat $1 | grep "#define LUA_RELEASE[ ]" | cut -f2-`
- if [ $LUA_VERSION_NUM -ge 501 ]; then
- return 1;
+ if [ -n "$LUA_VER" ]; then
+ if [ "$LUA_VER" -eq $LUA_VERSION_NUM ]; then
+ return 1
+ else
+ return 0
+ fi
else
- return 0;
+ if [ $LUA_VERSION_NUM -ge 501 ]; then
+ return 1
+ else
+ return 0
+ fi
fi
}
@@ -185,7 +208,7 @@ if [ -z "$LUA_DIR" ]; then
break
fi
else
- for dir in `ls -d $prefix/include/lua* 2> /dev/null`; do
+ for dir in `ls -r -d $prefix/include/lua* 2> /dev/null`; do
if [ -e $dir/lua.h ]; then
test_lua_version $dir/lua.h
if [ $? -eq 1 ]; then
diff --git a/src/gcsd.c b/src/gcsd.c
index 1d7d163..5860884 100644
--- a/src/gcsd.c
+++ b/src/gcsd.c
@@ -59,6 +59,22 @@ extern const size_t gcsd_lua_bytecode_len;
#define LUA_MAIN_LOOP_FUNC "main_loop"
+#if LUA_VERSION_NUM > 501
+static const luaL_Reg gcsd_lualibs[] = {
+ {"_G", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_RAWIOLIBNAME, luaopen_rawio},
+ {LUA_TCPLIBNAME, luaopen_tcp},
+ {LUA_UTILLIBNAME, luaopen_util},
+ {LUA_TIMERLIBNAME, luaopen_timer},
+ {LUA_LOGLIBNAME, luaopen_log},
+ {LUA_SIGNALLIBNAME, luaopen_signal},
+ {NULL, NULL}
+};
+#else
static const luaL_Reg gcsd_lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
@@ -73,6 +89,7 @@ static const luaL_Reg gcsd_lualibs[] = {
{LUA_SIGNALLIBNAME, luaopen_signal},
{NULL, NULL}
};
+#endif
int init_defines(lua_State *L)
{
@@ -118,11 +135,19 @@ int init_defines(lua_State *L)
int init_main_loop(lua_State *L)
{
const luaL_Reg *lib = gcsd_lualibs;
+
+#if LUA_VERSION_NUM > 501
+ for (; lib->func; lib++) {
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1);
+ }
+#else
for (; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
+#endif
int ret = luaL_loadbuffer(L, gcsd_lua_bytecode, gcsd_lua_bytecode_len, "gcsd");
if(ret) {
diff --git a/src/l_log.c b/src/l_log.c
index 7fb4e79..229624a 100644
--- a/src/l_log.c
+++ b/src/l_log.c
@@ -90,7 +90,7 @@ static int l_log_printf(lua_State *L)
return 0;
}
-static const struct luaL_reg log_funcs [] = {
+static const struct luaL_Reg log_funcs [] = {
{ "init", l_log_init },
{ "close", l_log_close },
{ "add_target", l_log_add_target },
@@ -101,7 +101,14 @@ static const struct luaL_reg log_funcs [] = {
LUALIB_API int luaopen_log(lua_State *L)
{
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, log_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_LOGLIBNAME);
+#else
luaL_register(L, LUA_LOGLIBNAME, log_funcs);
+#endif
lua_pushliteral(L, "ERROR");
lua_pushinteger(L, ERROR);
lua_settable(L, -3);
diff --git a/src/l_rawio.c b/src/l_rawio.c
index 3ba2851..213b0c4 100644
--- a/src/l_rawio.c
+++ b/src/l_rawio.c
@@ -124,7 +124,7 @@ static int l_rawio_close(lua_State *L)
return 0;
}
-static const struct luaL_reg rawio_funcs [] = {
+static const struct luaL_Reg rawio_funcs [] = {
{ "open", l_rawio_open },
{ "setnonblock", l_rawio_setnonblock },
{ "write", l_rawio_write },
@@ -136,6 +136,13 @@ static const struct luaL_reg rawio_funcs [] = {
LUALIB_API int luaopen_rawio(lua_State *L)
{
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, rawio_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_RAWIOLIBNAME);
+#else
luaL_register(L, LUA_RAWIOLIBNAME, rawio_funcs);
+#endif
return 1;
}
diff --git a/src/l_sig_handler.c b/src/l_sig_handler.c
index 35d8c14..cb9ba79 100644
--- a/src/l_sig_handler.c
+++ b/src/l_sig_handler.c
@@ -63,7 +63,7 @@ static int l_signal_handle(lua_State *L)
return 1;
}
-static const struct luaL_reg signal_funcs [] = {
+static const struct luaL_Reg signal_funcs [] = {
{ "init", l_signal_init },
{ "stop", l_signal_stop },
{ "handle", l_signal_handle },
@@ -73,6 +73,13 @@ static const struct luaL_reg signal_funcs [] = {
LUALIB_API int luaopen_signal(lua_State *L)
{
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, signal_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_SIGNALLIBNAME);
+#else
luaL_register(L, LUA_SIGNALLIBNAME, signal_funcs);
+#endif
return 1;
}
diff --git a/src/l_tcp.c b/src/l_tcp.c
index d96742c..d06a251 100644
--- a/src/l_tcp.c
+++ b/src/l_tcp.c
@@ -400,7 +400,7 @@ static int l_tcp_endtostring(lua_State *L)
return 1;
}
-static const struct luaL_reg tcp_funcs [] = {
+static const struct luaL_Reg tcp_funcs [] = {
{ "server", l_tcp_server },
{ "accept", l_tcp_accept },
{ "client", l_tcp_client },
@@ -413,6 +413,13 @@ static const struct luaL_reg tcp_funcs [] = {
LUALIB_API int luaopen_tcp(lua_State *L)
{
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, tcp_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_TCPLIBNAME);
+#else
luaL_register(L, LUA_TCPLIBNAME, tcp_funcs);
+#endif
return 1;
}
diff --git a/src/l_timer.c b/src/l_timer.c
index dfe3135..c63f865 100644
--- a/src/l_timer.c
+++ b/src/l_timer.c
@@ -113,7 +113,7 @@ static int l_timer_cmp(lua_State *L)
return 1;
}
-static const struct luaL_reg timer_funcs [] = {
+static const struct luaL_Reg timer_funcs [] = {
{ "new", l_timer_new },
{ "now", l_timer_now },
{ "add", l_timer_add },
@@ -124,6 +124,13 @@ static const struct luaL_reg timer_funcs [] = {
LUALIB_API int luaopen_timer(lua_State *L)
{
- luaL_register(L, LUA_TIMERLIBNAME, timer_funcs);
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, timer_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_TIMERLIBNAME);
+#else
+ luaL_register(L, LUA_TIMERLIBNAME, timer_funcs);
+#endif
return 1;
}
diff --git a/src/l_util.c b/src/l_util.c
index dbe43a5..6f55000 100644
--- a/src/l_util.c
+++ b/src/l_util.c
@@ -44,6 +44,10 @@
#include "l_util.h"
+#if LUA_VERSION_NUM < 502
+#define lua_objlen lua_rawlen
+#endif
+
static int get_fd(lua_State *L)
{
if(!lua_istable(L, -1))
@@ -141,7 +145,7 @@ static char** table_to_argv(lua_State *L, const char* script, int index)
{
size_t n = 0;
if(lua_istable(L, index))
- n = lua_objlen(L, index);
+ n = lua_rawlen(L, index);
char** my_ptrptr = malloc((n+2)*sizeof(char*));
if(!my_ptrptr)
@@ -178,7 +182,7 @@ static char** table_to_evp(lua_State *L, int index)
if(!lua_istable(L, index))
return NULL;
- size_t n = lua_objlen(L, index);
+ size_t n = lua_rawlen(L, index);
char** my_ptrptr = malloc((n+1)*sizeof(char*));
if(!my_ptrptr)
return NULL;
@@ -445,7 +449,7 @@ static int l_util_kill(lua_State *L)
return 1;
}
-static const struct luaL_reg util_funcs [] = {
+static const struct luaL_Reg util_funcs [] = {
{ "select", l_util_select },
{ "exec", l_util_exec },
{ "waitpid", l_util_waitpid },
@@ -456,8 +460,14 @@ static const struct luaL_reg util_funcs [] = {
LUALIB_API int luaopen_util(lua_State *L)
{
- luaL_register(L, LUA_UTILLIBNAME, util_funcs);
+#if LUA_VERSION_NUM > 501
lua_newtable(L);
+ luaL_setfuncs(L, util_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_UTILLIBNAME);
+#else
+ luaL_register(L, LUA_UTILLIBNAME, util_funcs);
+#endif
lua_setfield(L, -2, LUA_UTILCHLIDRENNAME);
return 1;
}