set up arg array in lua

This commit is contained in:
2026-05-08 23:04:02 +01:00
parent 56c7d48e65
commit 9d91c35cae
+9 -1
View File
@@ -44,14 +44,22 @@ extern "C" fn handle_sigchld(_: libc::c_int) {
fn fork_lua(lua : &Lua, args: Vec<String>, fds: Vec<i32>) -> Option<i32> {
let pathname = &args[0];
let path = Path::new(pathname);
match fork() {
Ok(Fork::Parent(pid)) => Some(pid),
Ok(Fork::Child) => {
for (i, fd) in fds.iter().enumerate() {
unsafe { libc::dup2(*fd, i.try_into().unwrap()); }
};
let globals = lua.globals();
if let Ok(arg_table) = lua.create_table() {
for (i, arg) in args.iter().enumerate() {
arg_table.set(i, arg.clone());
}
globals.set("arg".to_string(), arg_table);
}
let chunk = lua.load(path);
match chunk.exec() {
Ok(()) => { exit(0); },