Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change chunk env to use luau's lua_load env parameter #442

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions mlua-sys/src/luau/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ pub unsafe fn luaL_loadbufferx(
mut size: usize,
name: *const c_char,
mode: *const c_char,
env: c_int
) -> c_int {
extern "C" {
fn free(p: *mut c_void);
Expand All @@ -345,12 +346,12 @@ pub unsafe fn luaL_loadbufferx(

if chunk_is_text {
let data = luau_compile_(data, size, ptr::null_mut(), &mut size);
let ok = luau_load(L, name, data, size, 0) == 0;
let ok = luau_load(L, name, data, size, env) == 0;
free(data as *mut c_void);
if !ok {
return LUA_ERRSYNTAX;
}
} else if luau_load(L, name, data, size, 0) != 0 {
} else if luau_load(L, name, data, size, env) != 0 {
return LUA_ERRSYNTAX;
}
LUA_OK
Expand All @@ -361,9 +362,9 @@ pub unsafe fn luaL_loadbuffer(
L: *mut lua_State,
data: *const c_char,
size: usize,
name: *const c_char,
name: *const c_char
) -> c_int {
luaL_loadbufferx(L, data, size, name, ptr::null())
luaL_loadbufferx(L, data, size, name, ptr::null(), 0)
}

#[inline(always)]
Expand Down
11 changes: 10 additions & 1 deletion src/state/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,22 @@ impl RawLua {
source.len(),
name.map(|n| n.as_ptr()).unwrap_or_else(ptr::null),
mode_str,
#[cfg(feature="luau")]
match &env {
Some(env) => {
self.push_ref(&env.0);
-1
}
_ => 0
},
) {
ffi::LUA_OK => {
if let Some(env) = env {
#[cfg(not(feature="luau"))]
self.push_ref(&env.0);
#[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
ffi::lua_setupvalue(state, -2, 1);
#[cfg(any(feature = "lua51", feature = "luajit", feature = "luau"))]
#[cfg(any(feature = "lua51", feature = "luajit"))]
ffi::lua_setfenv(state, -2);
}

Expand Down
Loading