From eea4ba9195bfa654869e6efd35f2dbb649051cc7 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Fri, 24 Nov 2023 17:07:38 -0600 Subject: [PATCH] fix: return `nil` if component doesn't exist in lua script. --- .../bones_scripting/src/lua/bindings/components.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/framework_crates/bones_scripting/src/lua/bindings/components.rs b/framework_crates/bones_scripting/src/lua/bindings/components.rs index ee02e4b177..9b7835d855 100644 --- a/framework_crates/bones_scripting/src/lua/bindings/components.rs +++ b/framework_crates/bones_scripting/src/lua/bindings/components.rs @@ -37,9 +37,16 @@ pub fn metatable(ctx: Context) -> Table { let ecsref = EcsRef { data: EcsRefData::Component(ComponentRef { store, entity }), path: default(), + }; + + // Return nil if the component is not present + if ecsref.borrow().schema_ref().is_err() { + stack.replace(ctx, Value::Nil); + return Ok(CallbackReturn::Return); } - .into_value(ctx); - stack.push_front(ecsref); + + let ecsref = ecsref.into_value(ctx); + stack.replace(ctx, ecsref); Ok(CallbackReturn::Return) }),