summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mlua-sys/Cargo.toml2
-rw-r--r--mlua-sys/src/luau/luacode.rs19
-rw-r--r--src/chunk.rs30
3 files changed, 40 insertions, 11 deletions
diff --git a/mlua-sys/Cargo.toml b/mlua-sys/Cargo.toml
index 727bff0..411964f 100644
--- a/mlua-sys/Cargo.toml
+++ b/mlua-sys/Cargo.toml
@@ -40,4 +40,4 @@ cfg-if = "1.0"
pkg-config = "0.3.17"
lua-src = { version = ">= 546.0.2, < 546.1.0", optional = true }
luajit-src = { version = ">= 210.5.0, < 210.6.0", optional = true }
-luau0-src = { version = "0.8.0", optional = true }
+luau0-src = { version = "0.9.0", optional = true }
diff --git a/mlua-sys/src/luau/luacode.rs b/mlua-sys/src/luau/luacode.rs
index 357ad25..16a97eb 100644
--- a/mlua-sys/src/luau/luacode.rs
+++ b/mlua-sys/src/luau/luacode.rs
@@ -1,12 +1,14 @@
//! Contains definitions from `luacode.h`.
use std::os::raw::{c_char, c_int, c_void};
-use std::slice;
+use std::{ptr, slice};
#[repr(C)]
+#[non_exhaustive]
pub struct lua_CompileOptions {
pub optimizationLevel: c_int,
pub debugLevel: c_int,
+ pub typeInfoLevel: c_int,
pub coverageLevel: c_int,
pub vectorLib: *const c_char,
pub vectorCtor: *const c_char,
@@ -14,6 +16,21 @@ pub struct lua_CompileOptions {
pub mutableGlobals: *const *const c_char,
}
+impl Default for lua_CompileOptions {
+ fn default() -> Self {
+ Self {
+ optimizationLevel: 1,
+ debugLevel: 1,
+ typeInfoLevel: 0,
+ coverageLevel: 0,
+ vectorLib: ptr::null(),
+ vectorCtor: ptr::null(),
+ vectorType: ptr::null(),
+ mutableGlobals: ptr::null(),
+ }
+ }
+}
+
extern "C-unwind" {
#[link_name = "luau_compile"]
pub fn luau_compile_(
diff --git a/src/chunk.rs b/src/chunk.rs
index f3db5de..16b35cc 100644
--- a/src/chunk.rs
+++ b/src/chunk.rs
@@ -122,6 +122,7 @@ pub enum ChunkMode {
pub struct Compiler {
optimization_level: u8,
debug_level: u8,
+ type_info_level: u8,
coverage_level: u8,
vector_lib: Option<String>,
vector_ctor: Option<String>,
@@ -144,6 +145,7 @@ impl Compiler {
Compiler {
optimization_level: 1,
debug_level: 1,
+ type_info_level: 0,
coverage_level: 0,
vector_lib: None,
vector_ctor: None,
@@ -176,6 +178,16 @@ impl Compiler {
self
}
+ /// Sets Luau type information level used to guide native code generation decisions.
+ ///
+ /// Possible values:
+ /// * 0 - generate for native modules (default)
+ /// * 1 - generate for all modules
+ pub const fn set_type_info_level(mut self, level: u8) -> Self {
+ self.type_info_level = level;
+ self
+ }
+
/// Sets Luau compiler code coverage level.
///
/// Possible values:
@@ -250,15 +262,15 @@ impl Compiler {
}
unsafe {
- let options = ffi::lua_CompileOptions {
- optimizationLevel: self.optimization_level as c_int,
- debugLevel: self.debug_level as c_int,
- coverageLevel: self.coverage_level as c_int,
- vectorLib: vector_lib.map_or(ptr::null(), |s| s.as_ptr()),
- vectorCtor: vector_ctor.map_or(ptr::null(), |s| s.as_ptr()),
- vectorType: vector_type.map_or(ptr::null(), |s| s.as_ptr()),
- mutableGlobals: mutable_globals_ptr,
- };
+ let mut options = ffi::lua_CompileOptions::default();
+ options.optimizationLevel = self.optimization_level as c_int;
+ options.debugLevel = self.debug_level as c_int;
+ options.typeInfoLevel = self.type_info_level as c_int;
+ options.coverageLevel = self.coverage_level as c_int;
+ options.vectorLib = vector_lib.map_or(ptr::null(), |s| s.as_ptr());
+ options.vectorCtor = vector_ctor.map_or(ptr::null(), |s| s.as_ptr());
+ options.vectorType = vector_type.map_or(ptr::null(), |s| s.as_ptr());
+ options.mutableGlobals = mutable_globals_ptr;
ffi::luau_compile(source.as_ref(), options)
}
}