summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-11-26 22:24:39 +0000
committerubq323 <ubq323@ubq323.website>2024-11-26 22:24:39 +0000
commit5317e768311a6386aa7c11c97d6890b8e3e06dfa (patch)
tree6b6f9c98b7f884d28276bdd40c99799ff5b8fbea
parentd74b39d248c0df708e62da2fbeea6e74552ec514 (diff)
convenience wrapper
-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;
}