Skip to content

Commit

Permalink
feat(cli): allow toggling JIT compilation
Browse files Browse the repository at this point in the history
* Lune now accepts the `LUNE_LUAU_JIT` to toggle JIT compilation of Luau
  code.
* The `Runtime` struct exposes the `with_jit_enabled` method to library
  consumers.
  • Loading branch information
CompeyDev committed Oct 15, 2024
1 parent 010cd36 commit c70769c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 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 @@ -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 {
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 @@ -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.
Expand Down

0 comments on commit c70769c

Please sign in to comment.