From de7029aa193fcbcbf90cdb79611a8e14a3921066 Mon Sep 17 00:00:00 2001 From: qwreey Date: Sat, 2 Nov 2024 14:17:00 +0000 Subject: [PATCH] Remove debug exports (#243) --- crates/lune-std-ffi/src/ffi/association.rs | 13 ----------- crates/lune-std-ffi/src/lib.rs | 8 +------ crates/lune/src/cli/run.rs | 2 +- crates/lune/src/rt/runtime.rs | 2 +- types/ffi.luau | 25 ++++++++++++++++++++-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/crates/lune-std-ffi/src/ffi/association.rs b/crates/lune-std-ffi/src/ffi/association.rs index b5c6265f..19382306 100644 --- a/crates/lune-std-ffi/src/ffi/association.rs +++ b/crates/lune-std-ffi/src/ffi/association.rs @@ -66,16 +66,3 @@ where _ => panic!(), } } - -// Allows reading of registry tables for debugging. -// This helps keep track of data being gc'd. -// However, for security and safety reasons, -// this will not be allowed unless debug build. -#[cfg(debug_assertions)] -pub fn get_table<'lua>(lua: &'lua Lua, regname: &str) -> LuaResult>> { - match lua.named_registry_value::(regname)? { - LuaValue::Nil => Ok(None), - LuaValue::Table(t) => Ok(Some(t)), - _ => panic!(), - } -} diff --git a/crates/lune-std-ffi/src/lib.rs b/crates/lune-std-ffi/src/lib.rs index f85a1bb9..35a2450f 100644 --- a/crates/lune-std-ffi/src/lib.rs +++ b/crates/lune-std-ffi/src/lib.rs @@ -21,18 +21,12 @@ use crate::{ */ pub fn module(lua: &Lua) -> LuaResult { let result = TableBuilder::new(lua)? - .with_values(export_fixed_types(lua)?)? .with_function("nullRef", |lua, ()| create_nullref(lua))? .with_function("box", |_lua, size: usize| Ok(BoxData::new(size)))? .with_function("open", |_lua, name: String| LibData::new(name))? .with_function("isInteger", |_lua, num: LuaValue| Ok(num.is_integer()))? + .with_values(export_fixed_types(lua)?)? .with_value("c", export_c(lua)?)?; - #[cfg(debug_assertions)] - let result = result.with_function("debugAssociation", |lua, str: String| { - println!("WARNING: ffi.debug_associate is GC debug function, which only works for debug build. Do not use this function in production level codes."); - ffi::association::get_table(lua, str.as_ref()) - })?; - result.build_readonly() } diff --git a/crates/lune/src/cli/run.rs b/crates/lune/src/cli/run.rs index 19eab0bc..8f198c48 100644 --- a/crates/lune/src/cli/run.rs +++ b/crates/lune/src/cli/run.rs @@ -46,7 +46,7 @@ impl RunCommand { // Create a new lune runtime with all globals & run the script let mut rt = Runtime::new() .with_args(self.script_args) - .set_unsafe_lib_enabled(self.r#unsafe); + .set_unsafe_library_enabled(self.r#unsafe); let result = rt .run(&script_display_name, strip_shebang(script_contents)) diff --git a/crates/lune/src/rt/runtime.rs b/crates/lune/src/rt/runtime.rs index b6028dda..daeb0fd7 100644 --- a/crates/lune/src/rt/runtime.rs +++ b/crates/lune/src/rt/runtime.rs @@ -136,7 +136,7 @@ impl Runtime { Sets arguments to give in `process.args` for Lune scripts. */ #[must_use] - pub fn set_unsafe_lib_enabled(self, enabled: bool) -> Self { + pub fn set_unsafe_library_enabled(self, enabled: bool) -> Self { lune_std::set_unsafe_library_enabled(self.inner.lua(), enabled); self } diff --git a/types/ffi.luau b/types/ffi.luau index a60c6ee4..e524b203 100644 --- a/types/ffi.luau +++ b/types/ffi.luau @@ -415,7 +415,7 @@ export type CFnInfo = { Create a callable from reference. - @return Struct array type + @return A callable ]=] callable: (self: CFnInfo, functionRef: RefData) -> CallableData, --[=[ @@ -425,7 +425,7 @@ export type CFnInfo = { Create a closure from lua function. - @return A closure. + @return A closure ]=] closure: (self: CFnInfo, (ret: RefData, ...RefData) -> ()) -> ClosureData, } @@ -467,7 +467,28 @@ export type CStructInfo = { ]=] ptr: (self: CStructInfo) -> CPtrInfo, + --[=[ + @within CSturctInfo + @tag Method + @method box + + Create a box with initial value. + + @param table The array of field values + @return A box + ]=] box: (self: CStructInfo, table: { any }) -> BoxData, + --[=[ + @within CSturctInfo + @tag Method + @method readData + + Read a lua table from reference or box. + + @param target Target to read data from + @param offset Offset to read data from + @return A table + ]=] readData: (self: CStructInfo, target: RefData | BoxData, offset: number?) -> { any }, writeData: ( self: CStructInfo,