set up arg array in lua
This commit is contained in:
+9
-1
@@ -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); },
|
||||
|
||||
Reference in New Issue
Block a user