Skip to content

Commit 317ce7c

Browse files
committed
Add Lua::set_fflag() to control Luau feature flags
1 parent 3a44729 commit 317ce7c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

mlua-sys/src/luau/lua.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,8 @@ pub struct lua_Callbacks {
553553
extern "C" {
554554
pub fn lua_callbacks(L: *mut lua_State) -> *mut lua_Callbacks;
555555
}
556+
557+
// Functions from customization lib
558+
extern "C" {
559+
pub fn luau_setfflag(name: *const c_char, value: c_int) -> c_int;
560+
}

src/lua.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,20 @@ impl Lua {
12881288
unsafe { (*self.extra.get()).enable_jit = enable };
12891289
}
12901290

1291+
/// Sets Luau feature flag (global setting).
1292+
///
1293+
/// See https://github.com/luau-lang/luau/blob/master/CONTRIBUTING.md#feature-flags for details.
1294+
#[cfg(feature = "luau")]
1295+
#[doc(hidden)]
1296+
pub fn set_fflag(name: &str, enabled: bool) -> StdResult<(), ()> {
1297+
if let Ok(name) = CString::new(name) {
1298+
if unsafe { ffi::luau_setfflag(name.as_ptr(), enabled as c_int) != 0 } {
1299+
return Ok(());
1300+
}
1301+
}
1302+
Err(())
1303+
}
1304+
12911305
/// Returns Lua source code as a `Chunk` builder type.
12921306
///
12931307
/// In order to actually compile or run the resulting code, you must call [`Chunk::exec`] or

tests/luau.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,9 @@ fn test_buffer() -> Result<()> {
484484

485485
Ok(())
486486
}
487+
488+
#[test]
489+
fn test_fflags() {
490+
// We cannot really on any particular feature flag to be present
491+
assert!(Lua::set_fflag("UnknownFlag", true).is_err());
492+
}

0 commit comments

Comments
 (0)