Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toggling Luau's JIT in the CLI #265

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
12 changes: 10 additions & 2 deletions crates/lune/src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::process::ExitCode;
use std::{env, process::ExitCode};

use anyhow::{Context, Result};
use clap::Parser;
Expand Down Expand Up @@ -41,7 +41,15 @@ impl RunCommand {
};

// Create a new lune runtime with all globals & run the script
let mut rt = Runtime::new().with_args(self.script_args);
let mut rt = 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"
)
);

let result = rt
.run(&script_display_name, strip_shebang(script_contents))
Expand Down
9 changes: 9 additions & 0 deletions crates/lune/src/rt/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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.

Expand Down
Loading