summaryrefslogtreecommitdiffstats
path: root/src/lua.c
diff options
context:
space:
mode:
authorRobin Stern <robinstern1290@gmail.com>2021-03-22 21:23:56 -0700
committerRobin Stern <robinstern1290@gmail.com>2021-03-22 21:23:56 -0700
commitda2c08799d4e0dab7a37f1df23245d6cf620ae49 (patch)
tree29171ad9b784c6d787c0c7d2b96b9d674060dc17 /src/lua.c
parenteb71c73868520db7fcd707698cbbe2a23d773c90 (diff)
Enabled higher versisons of lua by making compile independent of user's lua version. Now version to link to is not hard-coded, so it sc-im will link to whatever lua version user has installed as their default lua. If lua is not found, Makefile then checks for luajit & links to luajit instead. Given lua is checked before luajit, newer compiles will always link to latest version of lua user installs, this is what most users would care about. For advanced users who care about high-performance of luaJIT & do not mind keeping their code compliant to Lua 5.1 & have both lua+luaJIT installed on their machines, they can comment part of Makefile (or remove lua from pkg-config path) to force sc-im to link to luaJIT.
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lua.c b/src/lua.c
index fd54bb5..d7f6259 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -295,7 +295,7 @@ LC_NUMBER2(curcol,curcol)
LC_NUMBER2(maxcols,maxcols)
LC_NUMBER2(maxrows,maxrows)
-static const luaL_reg sclib[] = {
+static const luaL_Reg sclib[] = {
{ "lgetnum", l_getnum },
{ "lsetnum", l_setnum },
{ "lsetform", l_setform },
@@ -312,6 +312,13 @@ static const luaL_reg sclib[] = {
{NULL,NULL}
};
+static int registerLuaFuncs(lua_State *L) {
+#if LUA_VERSION_NUM >= 502
+ luaL_newlib(L, sclib); /* Load SC specific LUA commands after init.lua exec*/
+#endif
+ return 1;
+}
+
/**
* \brief TODO Document doLuainit()
*
@@ -334,7 +341,13 @@ void doLuainit() {
if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
fprintf(stderr, "\nFATAL ERROR:\n Couldn't initialized Lua: %s\n\n", lua_tostring(L,-1));
}
+
+
+#if LUA_VERSION_NUM >= 502
+ luaL_requiref(L, "sc", registerLuaFuncs, 1); /* sc = require("sc") */
+#else
luaL_register(L, "sc", sclib); /* Load SC specific LUA commands after init.lua exec*/
+#endif
return;
}