diff --git a/src/compile.rs b/src/compile.rs index 3cddba1..a54cc8e 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -257,6 +257,27 @@ mod tests { assert_eq!(load_result, Ok(())); } + #[test] + fn cloned_compiler() { + let compiler = { + let original_compiler = Compiler::new(); + original_compiler.clone() + }; + + // has an effect so cant be optimized out entirely + let result = compiler.compile("v()"); + + assert!(result.is_ok(), "Expected result to be a success"); + assert!( + result.bytecode().is_some(), + "Expected resultant bytecode to be some" + ); + assert!( + result.bytecode().is_some_and(|v| !v.is_empty()), + "Expected resultant bytecode to be non-empty" + ); + } + #[test] fn compiler_error() { let compiler = Compiler::new(); diff --git a/src/lib.rs b/src/lib.rs index 2af8071..065dd87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1157,7 +1157,7 @@ impl Luau { let success = unsafe { luau_load( self.state, - chunk_name.map(CStr::as_ptr).unwrap_or(null()), + chunk_name.unwrap_or(c"").as_ptr(), bytecode.as_ptr() as _, bytecode.len(), env, @@ -1327,6 +1327,10 @@ mod tests { assert!(load_result.is_ok(), "Load result should be Ok"); + let load_result = luau.load(Some(c"test"), result.bytecode().unwrap(), 0); + + assert!(load_result.is_ok(), "Load result should be Ok"); + luau.codegen(-1); luau.call(0, 0); @@ -1590,6 +1594,24 @@ mod tests { matches!(status, LuauStatus::LUA_ERRRUN), "Expected there to be a runtime error." ); + + luau.push_function( + |l| { + l.check_args(1, None); + + 0 + }, + Some(c"test"), + 0, + ); + + let status = luau.call(0, 0); + + assert!( + matches!(status, LuauStatus::LUA_ERRRUN), + "Expected there to be a runtime error." + ); + } #[test]