Skip to content

Commit b46cad1

Browse files
committed
Support Luau v0.629
1 parent f2d48ce commit b46cad1

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ erased-serde = { version = "0.4", optional = true }
5555
serde-value = { version = "0.7", optional = true }
5656
parking_lot = { version = "0.12", optional = true }
5757

58-
ffi = { package = "mlua-sys", version = "0.6.0", path = "mlua-sys" }
58+
ffi = { package = "mlua-sys", version = "0.6.1", path = "mlua-sys" }
5959

6060
[target.'cfg(unix)'.dependencies]
6161
libloading = { version = "0.8", optional = true }

mlua-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mlua-sys"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
authors = ["Aleksandr Orlenko <zxteam@pm.me>"]
55
rust-version = "1.71"
66
edition = "2021"
@@ -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.9.0", optional = true }
43+
luau0-src = { version = "0.10.0", optional = true }

mlua-sys/src/luau/lua.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ extern "C-unwind" {
288288
pub fn lua_setuserdatatag(L: *mut lua_State, idx: c_int, tag: c_int);
289289
pub fn lua_setuserdatadtor(L: *mut lua_State, tag: c_int, dtor: Option<lua_Destructor>);
290290
pub fn lua_getuserdatadtor(L: *mut lua_State, tag: c_int) -> Option<lua_Destructor>;
291+
pub fn lua_setuserdatametatable(L: *mut lua_State, tag: c_int, idx: c_int);
292+
pub fn lua_getuserdatametatable(L: *mut lua_State, tag: c_int);
291293
pub fn lua_setlightuserdataname(L: *mut lua_State, tag: c_int, name: *const c_char);
292294
pub fn lua_getlightuserdataname(L: *mut lua_State, tag: c_int) -> *const c_char;
293295
pub fn lua_clonefunction(L: *mut lua_State, idx: c_int);

mlua-sys/src/luau/luacode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct lua_CompileOptions {
1414
pub vectorCtor: *const c_char,
1515
pub vectorType: *const c_char,
1616
pub mutableGlobals: *const *const c_char,
17+
pub userdataTypes: *const *const c_char,
1718
}
1819

1920
impl Default for lua_CompileOptions {
@@ -27,6 +28,7 @@ impl Default for lua_CompileOptions {
2728
vectorCtor: ptr::null(),
2829
vectorType: ptr::null(),
2930
mutableGlobals: ptr::null(),
31+
userdataTypes: ptr::null(),
3032
}
3133
}
3234
}

src/chunk.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub struct Compiler {
128128
vector_ctor: Option<String>,
129129
vector_type: Option<String>,
130130
mutable_globals: Vec<String>,
131+
userdata_types: Vec<String>,
131132
}
132133

133134
#[cfg(any(feature = "luau", doc))]
@@ -151,6 +152,7 @@ impl Compiler {
151152
vector_ctor: None,
152153
vector_type: None,
153154
mutable_globals: Vec::new(),
155+
userdata_types: Vec::new(),
154156
}
155157
}
156158

@@ -230,6 +232,13 @@ impl Compiler {
230232
self
231233
}
232234

235+
/// Sets a list of userdata types that will be included in the type information.
236+
#[must_use]
237+
pub fn set_userdata_types(mut self, types: Vec<String>) -> Self {
238+
self.userdata_types = types;
239+
self
240+
}
241+
233242
/// Compiles the `source` into bytecode.
234243
pub fn compile(&self, source: impl AsRef<[u8]>) -> Vec<u8> {
235244
use std::os::raw::c_int;
@@ -245,22 +254,26 @@ impl Compiler {
245254
let vector_type = vector_type.and_then(|t| CString::new(t).ok());
246255
let vector_type = vector_type.as_ref();
247256

248-
let mutable_globals = self
249-
.mutable_globals
250-
.iter()
251-
.map(|name| CString::new(name.clone()).ok())
252-
.collect::<Option<Vec<_>>>()
253-
.unwrap_or_default();
254-
let mut mutable_globals = mutable_globals
255-
.iter()
256-
.map(|s| s.as_ptr())
257-
.collect::<Vec<_>>();
258-
let mut mutable_globals_ptr = ptr::null();
259-
if !mutable_globals.is_empty() {
260-
mutable_globals.push(ptr::null());
261-
mutable_globals_ptr = mutable_globals.as_ptr();
257+
macro_rules! vec2cstring_ptr {
258+
($name:ident, $name_ptr:ident) => {
259+
let $name = self
260+
.$name
261+
.iter()
262+
.map(|name| CString::new(name.clone()).ok())
263+
.collect::<Option<Vec<_>>>()
264+
.unwrap_or_default();
265+
let mut $name = $name.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();
266+
let mut $name_ptr = ptr::null();
267+
if !$name.is_empty() {
268+
$name.push(ptr::null());
269+
$name_ptr = $name.as_ptr();
270+
}
271+
};
262272
}
263273

274+
vec2cstring_ptr!(mutable_globals, mutable_globals_ptr);
275+
vec2cstring_ptr!(userdata_types, userdata_types_ptr);
276+
264277
unsafe {
265278
let mut options = ffi::lua_CompileOptions::default();
266279
options.optimizationLevel = self.optimization_level as c_int;
@@ -271,6 +284,7 @@ impl Compiler {
271284
options.vectorCtor = vector_ctor.map_or(ptr::null(), |s| s.as_ptr());
272285
options.vectorType = vector_type.map_or(ptr::null(), |s| s.as_ptr());
273286
options.mutableGlobals = mutable_globals_ptr;
287+
options.userdataTypes = userdata_types_ptr;
274288
ffi::luau_compile(source.as_ref(), options)
275289
}
276290
}

0 commit comments

Comments
 (0)