summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-11-21 18:05:34 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-11-21 18:05:34 +0000
commit6dc0facc6fbf04c12e681bf641ad413f49d29a65 (patch)
treef0e15550472ec6d85512db95b8e47a84a8d224e9
parentutil.exec now supports arguments (diff)
environment pointer works now at exec
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@46 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--src/l_util.c37
-rw-r--r--src/main_loop.lua2
2 files changed, 27 insertions, 12 deletions
diff --git a/src/l_util.c b/src/l_util.c
index 1a13721..0b417ac 100644
--- a/src/l_util.c
+++ b/src/l_util.c
@@ -145,11 +145,10 @@ static int l_util_select(lua_State *L)
static char** table_to_argv(lua_State *L, const char* script, int index)
{
size_t n = 0;
- if(lua_istable(L, 2))
+ if(lua_istable(L, index))
n = lua_objlen(L, index);
- char** my_ptrptr;
- my_ptrptr = malloc((n+2)*sizeof(char*));
+ char** my_ptrptr = malloc((n+2)*sizeof(char*));
if(!my_ptrptr)
return NULL;
@@ -181,15 +180,31 @@ static char** table_to_argv(lua_State *L, const char* script, int index)
static char** table_to_evp(lua_State *L, int index)
{
- /* lua_pushnil(L); */
- /* int i = 0; */
- /* while(lua_next(L, index) != 0) { */
-
+ if(!lua_istable(L, index))
+ return NULL;
- /* lua_pop(L, 1); */
- /* i++; */
- /* } */
- return NULL;
+ size_t n = lua_objlen(L, index);
+ char** my_ptrptr = malloc((n+1)*sizeof(char*));
+ if(!my_ptrptr)
+ return NULL;
+
+ int i;
+ for(i = 0; i < n; ++i) {
+ lua_pushinteger(L, i+1);
+ lua_gettable(L, index);
+ my_ptrptr[i] = strdup(luaL_checkstring(L, -1));
+ lua_pop(L, 1);
+ if(!my_ptrptr[i]) {
+ i--;
+ for(; i >= 0; --i)
+ free(my_ptrptr[i]);
+
+ free(my_ptrptr);
+ return NULL;
+ }
+ }
+ my_ptrptr[n] = NULL;
+ return my_ptrptr;
}
void free_ptrptr(char** ptrptr)
diff --git a/src/main_loop.lua b/src/main_loop.lua
index 1ebb75d..14f83a2 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -74,7 +74,7 @@ function main_loop(opt)
log.printf(log.NOTICE, "main_loop started")
local sig = signal.init()
- local pid, err = util.exec("./tmp.sh", { "hello world", "gcsd!" })
+ local pid, err = util.exec("./tmp.sh", { "hello world", "gcsd!" }, { "gcsd=super", "dscg=repus" })
if(pid == nil) then
log.printf(log.DEBUG, "exec script failed: %s", err)
else