diff --git a/crates/lune/src/cli/run.rs b/crates/lune/src/cli/run.rs index 35e523e6..c180e6ab 100644 --- a/crates/lune/src/cli/run.rs +++ b/crates/lune/src/cli/run.rs @@ -1,4 +1,4 @@ -use std::process::ExitCode; +use std::{env, process::ExitCode}; use anyhow::{Context, Result}; use clap::Parser; @@ -43,6 +43,13 @@ impl RunCommand { // Create a new lune object with all globals & run the script let result = Runtime::new() .with_args(self.script_args) + // Enable JIT compilation unless it was requested to be disabled + .with_jit( + !matches!( + env::var("LUNE_LUAU_JIT").ok(), + Some(jit_enabled) if jit_enabled == "0" || jit_enabled == "false" || jit_enabled == "off" + ) + ) .run(&script_display_name, strip_shebang(script_contents)) .await; Ok(match result { diff --git a/crates/lune/src/rt/runtime.rs b/crates/lune/src/rt/runtime.rs index 1aa2acec..641e7bb2 100644 --- a/crates/lune/src/rt/runtime.rs +++ b/crates/lune/src/rt/runtime.rs @@ -131,6 +131,15 @@ impl Runtime { self } + /** + Enables or disables JIT compilation. + */ + #[must_use] + pub fn with_jit(self, enabled: bool) -> Self { + self.inner.lua().enable_jit(enabled); + self + } + /** Runs a Lune script inside of the current runtime.