summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--run.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/run.c b/run.c
index 27ea514..c1b2ced 100644
--- a/run.c
+++ b/run.c
@@ -53,11 +53,6 @@ int echofork(char *str, size_t len, int fd) {
}
}
-char *p1[] = {"sed","-e","s/a/b/g",NULL};
-char *p2[] = {"tac",NULL};
-char *p3[] = {"sed","-e","s/fish/PIG/",NULL};
-char *p4[] = {"rev",NULL};
-
void empipe(int pipefd[2]) {
CKE(pipe(pipefd), "pipe");
fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
@@ -180,7 +175,29 @@ finish:
return 1;
}
+int convienience_wrapper(lua_State *L) {
+ luaL_checktype(L, 1, LUA_TTABLE);
+ if (lua_gettop(L) != 1) return luaL_error(L, "run needs exactly 1 argument");
+ size_t tlen = lua_rawlen(L, 1);
+ if (tlen == 0) return luaL_error(L, "run's argument can't have 0 length");
+ int ty = lua_rawgeti(L, 1, 1);
+ lua_pop(L, 1);
+ if (ty == LUA_TSTRING) {
+ // x1 = {"a","b","c",input="ahaha"}
+ // x2 := {x1,input="ahaha"}
+ lua_newtable(L);
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, 2, 1);
+ lua_pushliteral(L, "input");
+ lua_pushliteral(L, "input");
+ lua_rawget(L, 1);
+ lua_rawset(L, 2);
+ lua_replace(L, 1);
+ }
+ return do_the_thing(L);
+}
+
int luaopen_run(lua_State *L) {
- lua_pushcfunction(L, &do_the_thing);
+ lua_pushcfunction(L, &convienience_wrapper);
return 1;
}