Skip to content

Commit

Permalink
use LuaJIT instead of Lua 5.1 as default interpreter
Browse files Browse the repository at this point in the history
- add "new scripting-no-jit feature" flag to optionally disable JIT support

- explicitly disable FFI, Jit, Debug and also the Package lib, so LuaJit and Lua51 scripts are mostly compatible
  • Loading branch information
emuell committed Jun 27, 2024
1 parent 3e30be2 commit b78927c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exclude = ["assets", "examples"]
categories = ["audio", "midi", "sequencer"]

[dependencies]
# required
lazy_static = { version = "^1.4" }
anyhow = { version = "^1.0" }
paste = { version = "^1.0" }
Expand All @@ -20,21 +19,23 @@ rand_xoshiro = { version = "^0.6" }
fraction = { version = "^0.15" }
pest = { version = "^2.7" }
pest_derive = { version = "^2.7" }

# optional -> dhat-profiler
dhat = { version = "^0.3", optional = true }
# optional -> scripting
mlua = { version = "^0.9", features = [
"lua51",
"vendored",
"macros",
"unstable",
], optional = true }

# optional -> player
crossbeam-channel = { version = "^0.5", optional = true }
afplay = { git = "https://github.com/emuell/afplay", default-features = false, features = [
"cpal-output",
], optional = true }

# optional -> scripting
mlua = { version = "^0.9", default-features = false, features = [
"vendored",
"macros",
"unstable",
], optional = true }

[dev-dependencies]
notify = { version = "^6.1" }
ctrlc = { version = "^3.4" }
Expand All @@ -45,8 +46,10 @@ debug = 1

[features]
dhat-profiler = ["dhat"]
scripting = ["mlua"]
player = ["crossbeam-channel", "afplay"]
scripting = ["mlua", "mlua/luajit"]
scripting-no-jit = ["mlua", "mlua/lua51"]
# NB: disable default-features when enabling no-jit!
default = ["scripting"]

[lib]
Expand Down
4 changes: 2 additions & 2 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ mod benchmarks;

// ---------------------------------------------------------------------------------------------

#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
criterion_main!(
benchmarks::scripted::scripted, //
benchmarks::rhythm::rhythm,
benchmarks::cycle::cycle,
);

#[cfg(not(feature = "scripting"))]
#[cfg(not(any(feature = "scripting", feature = "scripting-no-jit")))]
criterion_main!(
benchmarks::rhythm::rhythm, //
benchmarks::cycle::cycle,
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod cycle;
pub(crate) mod rhythm;
#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub(crate) mod scripted;
3 changes: 2 additions & 1 deletion src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ impl LuaAppData {
pub(crate) fn new_engine() -> LuaResult<(Lua, LuaTimeoutHook)> {
// create a new lua instance with the allowed std libraries
let lua = Lua::new_with(
LuaStdLib::STRING | LuaStdLib::TABLE | LuaStdLib::MATH | LuaStdLib::PACKAGE,
// Only basics: no OS, IO, PACKAGE, DEBUG, FFI!
LuaStdLib::STRING | LuaStdLib::TABLE | LuaStdLib::MATH,
LuaOptions::default(),
)
.expect("Failed to create a new lua engine");
Expand Down
4 changes: 2 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub mod cycle;
pub mod empty;
pub mod fixed;
pub mod mutated;
#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub mod scripted;
#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub mod scripted_cycle;

// -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{BeatTimeBase, PulseIterItem};
// -------------------------------------------------------------------------------------------------

pub mod probability;
#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub mod scripted;

// -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub use phrase::Phrase;
pub mod sequence;
pub use sequence::Sequence;

#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub mod bindings;

#[cfg(feature = "player")]
Expand Down
2 changes: 1 addition & 1 deletion src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{BeatTimeBase, PulseIterItem};
pub mod empty;
pub mod euclidean;
pub mod fixed;
#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
pub mod scripted;

// -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use super::{
TimeBase,
};

#[cfg(feature = "scripting")]
#[cfg(any(feature = "scripting", feature = "scripting-no-jit"))]
// all public scripting types
pub use super::{
bindings::{
Expand Down
4 changes: 2 additions & 2 deletions src/rhythm/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use fraction::{ConstOne, ConstZero, Fraction, ToPrimitive};

#[cfg(test)]
#[cfg(all(any(feature = "scripting", feature = "scripting-no-jit"), test))]
use std::borrow::BorrowMut;

use crate::{
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<Step: GenericRhythmTimeStep, Offset: GenericRhythmTimeStep> GenericRhythm<S
self.pattern.borrow()
}
/// Get mut access the current pattern (only allowed in tests).
#[cfg(test)]
#[cfg(all(any(feature = "scripting", feature = "scripting-no-jit"), test))]
pub(crate) fn pattern_mut(&mut self) -> &mut dyn Pattern {
self.pattern.borrow_mut()
}
Expand Down

0 comments on commit b78927c

Please sign in to comment.