summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anylike.org>2015-05-09 22:09:45 +0000
committerChristian Pointner <equinox@anylike.org>2015-05-09 22:09:45 +0000
commit73621e5c43ed3426f4e4775f9031bf83b4a5e3fc (patch)
treef3ab8c076786feef52cb84397f09dfd3e8100207
parentadded support for clang (diff)
added support for Lua 5.2
-rw-r--r--src/anylike.c22
-rwxr-xr-xsrc/configure32
-rw-r--r--src/l_crypt.c9
-rw-r--r--src/l_log.c9
-rw-r--r--src/l_sig_handler.c9
5 files changed, 73 insertions, 8 deletions
diff --git a/src/anylike.c b/src/anylike.c
index bc3bc7a..b509a5e 100644
--- a/src/anylike.c
+++ b/src/anylike.c
@@ -97,6 +97,19 @@ extern const uint32_t anylike_lua_bytecode_len;
#define LUA_MAIN_LOOP_FUNC "main_loop"
+#if LUA_VERSION_NUM > 501
+static const luaL_Reg anylike_lualibs[] = {
+ {"_G", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_LOGLIBNAME, luaopen_log},
+ {LUA_SIGNALLIBNAME, luaopen_signal},
+ {LUA_CRYPTLIBNAME, luaopen_crypt},
+ {NULL, NULL}
+};
+#else
static const luaL_Reg anylike_lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
@@ -108,15 +121,24 @@ static const luaL_Reg anylike_lualibs[] = {
{LUA_CRYPTLIBNAME, luaopen_crypt},
{NULL, NULL}
};
+#endif
int init_main_loop(lua_State *L)
{
const luaL_Reg *lib = anylike_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, anylike_lua_bytecode, anylike_lua_bytecode_len, "anylike");
if(ret) {
diff --git a/src/configure b/src/configure
index 75a26ac..a639634 100755
--- a/src/configure
+++ b/src/configure
@@ -59,6 +59,7 @@ print_usage() {
echo " --no-examples dont't install example files"
echo " --use-openssl use openssl instead of gnutls"
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"
}
@@ -98,6 +99,9 @@ do
--with-lua=*)
LUA_DIR=${arg#--with-lua=}
;;
+ --lua-version=*)
+ LUA_VER=${arg#--lua-version=}
+ ;;
--ebuild-compat)
EBUILD_COMPAT=1
;;
@@ -171,14 +175,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
}
diff --git a/src/l_crypt.c b/src/l_crypt.c
index 0f6b8df..124a487 100644
--- a/src/l_crypt.c
+++ b/src/l_crypt.c
@@ -40,7 +40,7 @@ static int l_crypt_test(lua_State *L)
return 1;
}
-static const struct luaL_reg crypt_funcs [] = {
+static const struct luaL_Reg crypt_funcs [] = {
{ "test", l_crypt_test },
{ NULL, NULL }
};
@@ -48,6 +48,13 @@ static const struct luaL_reg crypt_funcs [] = {
LUALIB_API int luaopen_crypt(lua_State *L)
{
+#if LUA_VERSION_NUM > 501
+ lua_newtable(L);
+ luaL_setfuncs(L, crypt_funcs, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, LUA_CRYPTLIBNAME);
+#else
luaL_register(L, LUA_CRYPTLIBNAME, crypt_funcs);
+#endif
return 1;
}
diff --git a/src/l_log.c b/src/l_log.c
index 528fe95..37e725e 100644
--- a/src/l_log.c
+++ b/src/l_log.c
@@ -89,7 +89,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 },
@@ -100,7 +100,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_sig_handler.c b/src/l_sig_handler.c
index 0bdcffc..7f016ce 100644
--- a/src/l_sig_handler.c
+++ b/src/l_sig_handler.c
@@ -84,7 +84,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 },
@@ -94,6 +94,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;
}