From 8b0edc8daebc45340a7e5cd85b78b627bf210ea8 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 25 Mar 2023 11:12:09 +0100 Subject: [PATCH] Fix access of roblox instance reference properties when they are not set --- .justfile | 4 ++++ packages/lib-roblox/src/instance/mod.rs | 14 +++++++++----- tests/roblox/instance/properties.luau | 8 ++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.justfile b/.justfile index f7ab73c..5760c8c 100644 --- a/.justfile +++ b/.justfile @@ -1,3 +1,7 @@ +# Run an individual test using the Lune CLI +run-test TEST_NAME: + cargo run -- "tests/{{TEST_NAME}}" + # Run tests for the Lune library test: cargo test --package lune -- --test-threads 1 diff --git a/packages/lib-roblox/src/instance/mod.rs b/packages/lib-roblox/src/instance/mod.rs index 5762314..c6b8e0f 100644 --- a/packages/lib-roblox/src/instance/mod.rs +++ b/packages/lib-roblox/src/instance/mod.rs @@ -6,7 +6,7 @@ use std::{ use mlua::prelude::*; use rbx_dom_weak::{ - types::{Ref as DomRef, Variant as DomValue}, + types::{Ref as DomRef, Variant as DomValue, VariantType as DomType}, Instance as DomInstance, InstanceBuilder as DomInstanceBuilder, WeakDom, }; @@ -739,10 +739,14 @@ impl LuaUserData for Instance { } else if let Some(prop_default) = info.value_default { Ok(LuaValue::dom_value_to_lua(lua, prop_default)?) } else if info.value_type.is_some() { - Err(LuaError::RuntimeError(format!( - "Failed to get property '{}' - missing default value", - prop_name - ))) + if info.value_type == Some(DomType::Ref) { + Ok(LuaValue::Nil) + } else { + Err(LuaError::RuntimeError(format!( + "Failed to get property '{}' - missing default value", + prop_name + ))) + } } else { Err(LuaError::RuntimeError(format!( "Failed to get property '{}' - malformed property info", diff --git a/tests/roblox/instance/properties.luau b/tests/roblox/instance/properties.luau index a8a810c..40709a7 100644 --- a/tests/roblox/instance/properties.luau +++ b/tests/roblox/instance/properties.luau @@ -47,3 +47,11 @@ assert(meshPart.Anchored == false) assert(meshPart.Material == Enum.Material.Plastic) assert(meshPart.Size == Vector3.new(4, 1.2, 2)) assert(meshPart.CustomPhysicalProperties == nil) + +-- Instance reference properties should work + +local objectValue = Instance.new("ObjectValue") + +assert(objectValue.Value == nil) +objectValue.Value = meshPart +assert(objectValue.Value == meshPart)