mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Add Lua::set_fflag() to control Luau feature flags
This commit is contained in:
@@ -553,3 +553,8 @@ pub struct lua_Callbacks {
|
||||
extern "C" {
|
||||
pub fn lua_callbacks(L: *mut lua_State) -> *mut lua_Callbacks;
|
||||
}
|
||||
|
||||
// Functions from customization lib
|
||||
extern "C" {
|
||||
pub fn luau_setfflag(name: *const c_char, value: c_int) -> c_int;
|
||||
}
|
||||
|
||||
+14
@@ -1288,6 +1288,20 @@ impl Lua {
|
||||
unsafe { (*self.extra.get()).enable_jit = enable };
|
||||
}
|
||||
|
||||
/// Sets Luau feature flag (global setting).
|
||||
///
|
||||
/// See https://github.com/luau-lang/luau/blob/master/CONTRIBUTING.md#feature-flags for details.
|
||||
#[cfg(feature = "luau")]
|
||||
#[doc(hidden)]
|
||||
pub fn set_fflag(name: &str, enabled: bool) -> StdResult<(), ()> {
|
||||
if let Ok(name) = CString::new(name) {
|
||||
if unsafe { ffi::luau_setfflag(name.as_ptr(), enabled as c_int) != 0 } {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
|
||||
/// Returns Lua source code as a `Chunk` builder type.
|
||||
///
|
||||
/// In order to actually compile or run the resulting code, you must call [`Chunk::exec`] or
|
||||
|
||||
@@ -484,3 +484,9 @@ fn test_buffer() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fflags() {
|
||||
// We cannot really on any particular feature flag to be present
|
||||
assert!(Lua::set_fflag("UnknownFlag", true).is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user