diff --git a/src/arguments.rs b/src/arguments.rs index 791078a..5431444 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -6,7 +6,11 @@ use std::path::PathBuf; #[derive(Parser)] #[command(version = build_info::version_formatted())] pub struct Arguments { - /// Path to main Lua file + /// Path to Lua entrypoint #[arg(short, long)] pub script: Option, + + /// Code to execute after loading script + #[arg(short, long)] + pub exec: Option, } diff --git a/src/lua/mod.rs b/src/lua/mod.rs index 094c2e5..1603fbb 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -52,7 +52,7 @@ pub fn reload(lua: &Lua, sender: Option) -> Result<(), Error> { lua.load( &std::fs::read_to_string( lua.globals() - .get::("script_path") + .get::("SCRIPT_PATH") .map_err(Error::MissingPath)?, ) .map_err(Error::ReadFile)?, diff --git a/src/main.rs b/src/main.rs index 5dcd0f5..ba0a335 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,13 +54,17 @@ async fn main() -> anyhow::Result<()> { let lua = unsafe { Lua::unsafe_new() }; let globals = lua.globals(); - globals.set("script_path", &*script_path)?; lua::register_globals(&lua, &globals, event_listeners.clone())?; + globals.set("SCRIPT_PATH", &*script_path)?; lua.load( read_to_string(script_path) .expect(&(DEFAULT_SCRIPT_PATH.to_owned() + " should be in current directory")), ) .exec()?; + if let Some(code) = args.exec { + lua.load(code).exec()?; + } + let server = globals .get::("Server") .expect("Server should be in lua globals");