#include "base.hh" #include "lua.hh" #include #include #include "platform.hh" using std::malloc; using std::free; LUAEXT(get_ostype, ) { std::string str; get_system_flavour(str); lua_pushstring(L, str.c_str()); return 1; } LUAEXT(existsonpath, ) { const char *exe = luaL_checkstring(L, -1); lua_pushnumber(L, existsonpath(exe)); return 1; } LUAEXT(is_executable, ) { const char *path = luaL_checkstring(L, -1); lua_pushboolean(L, is_executable(path)); return 1; } LUAEXT(make_executable, ) { const char *path = luaL_checkstring(L, -1); lua_pushnumber(L, make_executable(path)); return 1; } LUAEXT(spawn, ) { int n = lua_gettop(L); const char *path = luaL_checkstring(L, 1); char **argv = (char**)malloc((n+1)*sizeof(char*)); int i; pid_t ret; if (argv==NULL) return 0; argv[0] = (char*)path; for (i=1; i(luaL_checknumber(L, -1)); int res; int ret; ret = process_wait(pid, &res); lua_pushnumber(L, res); lua_pushnumber(L, ret); return 2; } LUAEXT(kill, ) { int n = lua_gettop(L); pid_t pid = static_cast(luaL_checknumber(L, -2)); int sig; if (n>1) sig = static_cast(luaL_checknumber(L, -1)); else sig = SIGTERM; lua_pushnumber(L, process_kill(pid, sig)); return 1; } LUAEXT(sleep, ) { int seconds = static_cast(luaL_checknumber(L, -1)); lua_pushnumber(L, process_sleep(seconds)); return 1; } LUAEXT(get_pid, ) { pid_t pid = get_process_id(); lua_pushnumber(L, pid); return 1; } // Local Variables: // mode: C++ // fill-column: 76 // c-file-style: "gnu" // indent-tabs-mode: nil // End: // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: