summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2019-02-21 15:48:19 +0200
committerPanu Matilainen <pmatilai@redhat.com>2019-02-21 15:52:43 +0200
commit1c433661eaef022bba0fb957739058e78ea64588 (patch)
tree1ccf8a38722eee9da171e7708348e43cfb6f01cb
parent6974274db2cb5ea9eca085dadab117577dd5feb7 (diff)
downloadrpm-1c433661eaef022bba0fb957739058e78ea64588.tar.gz
Move lua os.exit() override from posix module to rpmlua
It was always an ugly hack and wrong to be in the posix module to begin with, this makes the initialization and all much saner. And is actually less code too.
-rw-r--r--luaext/lposix.c27
-rw-r--r--luaext/lposix.h1
-rw-r--r--rpmio/rpmlua.c19
3 files changed, 18 insertions, 29 deletions
diff --git a/luaext/lposix.c b/luaext/lposix.c
index c59091177..15a1cd606 100644
--- a/luaext/lposix.c
+++ b/luaext/lposix.c
@@ -897,30 +897,3 @@ LUALIB_API int luaopen_posix (lua_State *L)
return 1;
}
-/* RPM specific overrides for Lua standard library */
-
-static int exit_override(lua_State *L)
-{
- if (!_rpmlua_have_forked)
- return luaL_error(L, "exit not permitted in this context");
-
- exit(luaL_optinteger(L, 1, EXIT_SUCCESS));
-}
-
-static const luaL_Reg os_overrides[] =
-{
- {"exit", exit_override},
- {NULL, NULL}
-};
-
-#ifndef lua_pushglobaltable
-#define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
-#endif
-
-int luaopen_rpm_os(lua_State *L)
-{
- lua_pushglobaltable(L);
- luaL_openlib(L, "os", os_overrides, 0);
- return 0;
-}
-
diff --git a/luaext/lposix.h b/luaext/lposix.h
index 1f9afe980..e1e819cb3 100644
--- a/luaext/lposix.h
+++ b/luaext/lposix.h
@@ -2,6 +2,5 @@
#define LPOSIX_H
int luaopen_posix (lua_State *L);
-int luaopen_rpm_os (lua_State *L);
#endif
diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c
index ccd536422..9689e2aa8 100644
--- a/rpmio/rpmlua.c
+++ b/rpmio/rpmlua.c
@@ -87,6 +87,7 @@ static void *nextFileFuncParam = NULL;
static int luaopen_rpm(lua_State *L);
static int rpm_print(lua_State *L);
+static int rpm_exit(lua_State *L);
static int pusherror(lua_State *L, int code, const char *info)
{
@@ -115,6 +116,12 @@ rpmlua rpmluaGetGlobalState(void)
return lua;
}
+static const luaL_Reg os_overrides[] =
+{
+ {"exit", rpm_exit},
+ {NULL, NULL}
+};
+
rpmlua rpmluaNew()
{
rpmlua lua = NULL;
@@ -126,7 +133,6 @@ rpmlua rpmluaNew()
{"posix", luaopen_posix},
{"rex", luaopen_rex},
{"rpm", luaopen_rpm},
- {"os", luaopen_rpm_os},
{NULL, NULL},
};
@@ -147,6 +153,9 @@ rpmlua rpmluaNew()
lua_pushcfunction(L, rpm_print);
lua_setglobal(L, "print");
+ lua_pushglobaltable(L);
+ luaL_openlib(L, "os", os_overrides, 0);
+
lua_getglobal(L, "package");
lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua");
lua_setfield(L, -2, "path");
@@ -945,6 +954,14 @@ static int rpm_print (lua_State *L)
return 0;
}
+static int rpm_exit(lua_State *L)
+{
+ if (!_rpmlua_have_forked)
+ return luaL_error(L, "exit not permitted in this context");
+
+ exit(luaL_optinteger(L, 1, EXIT_SUCCESS));
+}
+
static int rpm_execute(lua_State *L)
{
const char *file = luaL_checkstring(L, 1);