summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2024-05-04 21:15:22 +0100
committerAlex Orlenko <zxteam@protonmail.com>2024-05-04 21:15:22 +0100
commit317ce7caa6984b5fda0282308b2e269ece26ae7a (patch)
treeb7019ff43c7eb052ee17468df57a46592c84fb81
parent3a44729a48e216fd581193a9f234ac6fb6c0c32a (diff)
downloadmlua-317ce7caa6984b5fda0282308b2e269ece26ae7a.zip
Add `Lua::set_fflag()` to control Luau feature flags
-rw-r--r--mlua-sys/src/luau/lua.rs5
-rw-r--r--src/lua.rs14
-rw-r--r--tests/luau.rs6
3 files changed, 25 insertions, 0 deletions
diff --git a/mlua-sys/src/luau/lua.rs b/mlua-sys/src/luau/lua.rs
index 3db6a7b..a2077e1 100644
--- a/mlua-sys/src/luau/lua.rs
+++ b/mlua-sys/src/luau/lua.rs
@@ -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;
+}
diff --git a/src/lua.rs b/src/lua.rs
index 35bdf4b..6def0c0 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -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
diff --git a/tests/luau.rs b/tests/luau.rs
index aedcc53..29af6cf 100644
--- a/tests/luau.rs
+++ b/tests/luau.rs
@@ -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());
+}