Skip to content

Commit

Permalink
Updates MDL
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Jul 21, 2022
1 parent f657ba1 commit 6bd7c89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
locenv = "0.5"
locenv-macros = "0.5"
locenv = "0.6"
locenv-macros = "0.6"
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use self::session::Session;
use locenv::api::LuaState;
use locenv::FunctionEntry;
use locenv::{create_table, new_userdata, push_value, set_functions, upvalue_index, FunctionEntry};
use locenv_macros::loader;
use std::os::raw::c_int;

Expand All @@ -14,13 +14,14 @@ const MODULE_FUNCTIONS: [FunctionEntry; 1] = [FunctionEntry {
const TYPE_SESSION: &str = "session";

extern "C" fn newsession(lua: *mut LuaState) -> c_int {
locenv::new_userdata(lua, Session::new());
new_userdata(lua, upvalue_index(1), Session::new());
1
}

#[loader]
extern "C" fn loader(lua: *mut LuaState) -> c_int {
locenv::create_table(lua, 0, MODULE_FUNCTIONS.len() as _);
locenv::set_functions(lua, &MODULE_FUNCTIONS, 0);
create_table(lua, 0, MODULE_FUNCTIONS.len() as _);
push_value(lua, 2); // Push Context.
set_functions(lua, &MODULE_FUNCTIONS, 1);
1
}
13 changes: 7 additions & 6 deletions src/session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::TYPE_SESSION;
use locenv::api::LuaState;
use locenv::{MethodEntry, Object, UserData};
use locenv::{check_string, error, upvalue_index, Context, MethodEntry, Object, UserData};
use std::os::raw::c_int;
use std::process::{Command, Stdio};

Expand All @@ -12,26 +12,27 @@ impl Session {
}

fn run(&mut self, lua: *mut LuaState) -> c_int {
let command = locenv::check_string(lua, 2);
let context = Context::from_lua(lua, upvalue_index(1));
let command = check_string(lua, 2);

// Launch sh.
let mut launcher = Command::new("sh");

launcher.current_dir(locenv::get_working_directory());
launcher.current_dir(context.working_directory());
launcher.arg("-ec");
launcher.arg(&command);
launcher.stdin(Stdio::null());

let status = match launcher.status() {
Ok(r) => r,
Err(e) => locenv::error!(lua, "failed to launch sh: {}", e),
Err(e) => error!(lua, "failed to launch sh: {}", e),
};

// Check status.
if !status.success() {
match status.code() {
Some(v) => locenv::error!(lua, "process exited with status {}", v),
None => locenv::error!(lua, "process terminated by signal"),
Some(v) => error!(lua, "process exited with status {}", v),
None => error!(lua, "process terminated by signal"),
}
}

Expand Down

0 comments on commit 6bd7c89

Please sign in to comment.