Skip to content

Commit 3d46fad

Browse files
committed
Update luau-src to v0.9
Mark `lua_CompileOptions` as non exhaustive
1 parent ffc4bd5 commit 3d46fad

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

mlua-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ cfg-if = "1.0"
4040
pkg-config = "0.3.17"
4141
lua-src = { version = ">= 546.0.2, < 546.1.0", optional = true }
4242
luajit-src = { version = ">= 210.5.0, < 210.6.0", optional = true }
43-
luau0-src = { version = "0.8.0", optional = true }
43+
luau0-src = { version = "0.9.0", optional = true }

mlua-sys/src/luau/luacode.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
//! Contains definitions from `luacode.h`.
22
33
use std::os::raw::{c_char, c_int, c_void};
4-
use std::slice;
4+
use std::{ptr, slice};
55

66
#[repr(C)]
7+
#[non_exhaustive]
78
pub struct lua_CompileOptions {
89
pub optimizationLevel: c_int,
910
pub debugLevel: c_int,
11+
pub typeInfoLevel: c_int,
1012
pub coverageLevel: c_int,
1113
pub vectorLib: *const c_char,
1214
pub vectorCtor: *const c_char,
1315
pub vectorType: *const c_char,
1416
pub mutableGlobals: *const *const c_char,
1517
}
1618

19+
impl Default for lua_CompileOptions {
20+
fn default() -> Self {
21+
Self {
22+
optimizationLevel: 1,
23+
debugLevel: 1,
24+
typeInfoLevel: 0,
25+
coverageLevel: 0,
26+
vectorLib: ptr::null(),
27+
vectorCtor: ptr::null(),
28+
vectorType: ptr::null(),
29+
mutableGlobals: ptr::null(),
30+
}
31+
}
32+
}
33+
1734
extern "C-unwind" {
1835
#[link_name = "luau_compile"]
1936
pub fn luau_compile_(

src/chunk.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub enum ChunkMode {
122122
pub struct Compiler {
123123
optimization_level: u8,
124124
debug_level: u8,
125+
type_info_level: u8,
125126
coverage_level: u8,
126127
vector_lib: Option<String>,
127128
vector_ctor: Option<String>,
@@ -144,6 +145,7 @@ impl Compiler {
144145
Compiler {
145146
optimization_level: 1,
146147
debug_level: 1,
148+
type_info_level: 0,
147149
coverage_level: 0,
148150
vector_lib: None,
149151
vector_ctor: None,
@@ -176,6 +178,16 @@ impl Compiler {
176178
self
177179
}
178180

181+
/// Sets Luau type information level used to guide native code generation decisions.
182+
///
183+
/// Possible values:
184+
/// * 0 - generate for native modules (default)
185+
/// * 1 - generate for all modules
186+
pub const fn set_type_info_level(mut self, level: u8) -> Self {
187+
self.type_info_level = level;
188+
self
189+
}
190+
179191
/// Sets Luau compiler code coverage level.
180192
///
181193
/// Possible values:
@@ -250,15 +262,15 @@ impl Compiler {
250262
}
251263

252264
unsafe {
253-
let options = ffi::lua_CompileOptions {
254-
optimizationLevel: self.optimization_level as c_int,
255-
debugLevel: self.debug_level as c_int,
256-
coverageLevel: self.coverage_level as c_int,
257-
vectorLib: vector_lib.map_or(ptr::null(), |s| s.as_ptr()),
258-
vectorCtor: vector_ctor.map_or(ptr::null(), |s| s.as_ptr()),
259-
vectorType: vector_type.map_or(ptr::null(), |s| s.as_ptr()),
260-
mutableGlobals: mutable_globals_ptr,
261-
};
265+
let mut options = ffi::lua_CompileOptions::default();
266+
options.optimizationLevel = self.optimization_level as c_int;
267+
options.debugLevel = self.debug_level as c_int;
268+
options.typeInfoLevel = self.type_info_level as c_int;
269+
options.coverageLevel = self.coverage_level as c_int;
270+
options.vectorLib = vector_lib.map_or(ptr::null(), |s| s.as_ptr());
271+
options.vectorCtor = vector_ctor.map_or(ptr::null(), |s| s.as_ptr());
272+
options.vectorType = vector_type.map_or(ptr::null(), |s| s.as_ptr());
273+
options.mutableGlobals = mutable_globals_ptr;
262274
ffi::luau_compile(source.as_ref(), options)
263275
}
264276
}

0 commit comments

Comments
 (0)