From a6c4459a3a4765411dd473ede1f4777c8f219c5a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 27 Aug 2009 12:08:02 +0200 Subject: [PATCH] luaa: replace os.execute() Signed-off-by: Julien Danjou --- luaa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/luaa.c b/luaa.c index b0232746d..6f046931c 100644 --- a/luaa.c +++ b/luaa.c @@ -236,6 +236,18 @@ luaAe_type(lua_State *L) return 1; } +/** Modified version of os.execute() which use spawn code to reset signal + * handlers correctly before exec()ing the new program. + * \param L The Lua VM state. + * \return The number of arguments pushed on stack. + */ +static int +luaAe_os_execute(lua_State *L) +{ + lua_pushinteger(L, spawn_system(luaL_optstring(L, 1, NULL))); + return 1; +} + /** Replace various standards Lua functions with our own. * \param L The Lua VM state. */ @@ -247,6 +259,11 @@ luaA_fixups(lua_State *L) lua_pushcfunction(L, luaA_mbstrlen); lua_setfield(L, -2, "wlen"); lua_pop(L, 1); + /* replace os.execute */ + lua_getglobal(L, "os"); + lua_pushcfunction(L, luaAe_os_execute); + lua_setfield(L, -2, "execute"); + lua_pop(L, 1); /* replace next */ lua_pushliteral(L, "next"); lua_pushcfunction(L, luaAe_next);