Fix access of roblox instance reference properties when they are not set

This commit is contained in:
Filip Tibell 2023-03-25 11:12:09 +01:00
parent 25f46c10a8
commit 8b0edc8dae
No known key found for this signature in database
3 changed files with 21 additions and 5 deletions

View file

@ -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

View file

@ -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() {
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",

View file

@ -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)