mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix erroring when setting nil attributes on instances in roblox lib
This commit is contained in:
parent
636d0bf277
commit
4f6f1835d2
4 changed files with 41 additions and 7 deletions
|
@ -21,8 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
- Fixed formatted values in tables not being separated by newlines
|
- Fixed formatted values in tables not being separated by newlines.
|
||||||
- Fixed panicking (crashing) when using `process.spawn` with a program that does not exist.
|
- Fixed panicking (crashing) when using `process.spawn` with a program that does not exist.
|
||||||
|
- Fixed `instance:SetAttribute("name", nil)` throwing an error and not removing the attribute.
|
||||||
|
|
||||||
## `0.8.4` - May 12th, 2024
|
## `0.8.4` - May 12th, 2024
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,10 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(m: &mut M) {
|
||||||
|lua, this, (attribute_name, lua_value): (String, LuaValue)| {
|
|lua, this, (attribute_name, lua_value): (String, LuaValue)| {
|
||||||
ensure_not_destroyed(this)?;
|
ensure_not_destroyed(this)?;
|
||||||
ensure_valid_attribute_name(&attribute_name)?;
|
ensure_valid_attribute_name(&attribute_name)?;
|
||||||
|
if lua_value.is_nil() || lua_value.is_null() {
|
||||||
|
this.remove_attribute(attribute_name);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
match lua_value.lua_to_dom_value(lua, None) {
|
match lua_value.lua_to_dom_value(lua, None) {
|
||||||
Ok(dom_value) => {
|
Ok(dom_value) => {
|
||||||
ensure_valid_attribute_value(&dom_value)?;
|
ensure_valid_attribute_value(&dom_value)?;
|
||||||
|
@ -163,6 +167,7 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(m: &mut M) {
|
||||||
}
|
}
|
||||||
Err(e) => Err(e.into()),
|
Err(e) => Err(e.into()),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
m.add_method("GetTags", |_, this, ()| {
|
m.add_method("GetTags", |_, this, ()| {
|
||||||
|
|
|
@ -442,6 +442,29 @@ impl Instance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Removes an attribute from the instance.
|
||||||
|
|
||||||
|
Note that this does not have an equivalent in the Roblox engine API,
|
||||||
|
but separating this from `set_attribute` lets `set_attribute` be more
|
||||||
|
ergonomic and not require an `Option<DomValue>` for the value argument.
|
||||||
|
The equivalent in the Roblox engine API would be `instance:SetAttribute(name, nil)`.
|
||||||
|
*/
|
||||||
|
pub fn remove_attribute(&self, name: impl AsRef<str>) {
|
||||||
|
let mut dom = INTERNAL_DOM.lock().expect("Failed to lock document");
|
||||||
|
let inst = dom
|
||||||
|
.get_by_ref_mut(self.dom_ref)
|
||||||
|
.expect("Failed to find instance in document");
|
||||||
|
if let Some(DomValue::Attributes(attributes)) =
|
||||||
|
inst.properties.get_mut(PROPERTY_NAME_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
attributes.remove(name.as_ref());
|
||||||
|
if attributes.is_empty() {
|
||||||
|
inst.properties.remove(PROPERTY_NAME_ATTRIBUTES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adds a tag to the instance.
|
Adds a tag to the instance.
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,11 @@ local folder = Instance.new("Folder")
|
||||||
folder:SetAttribute("Foo", "Bar")
|
folder:SetAttribute("Foo", "Bar")
|
||||||
assert(folder:GetAttribute("Foo") == "Bar")
|
assert(folder:GetAttribute("Foo") == "Bar")
|
||||||
|
|
||||||
|
-- Setting attributes to nil should work
|
||||||
|
|
||||||
|
folder:SetAttribute("Foo", nil)
|
||||||
|
assert(folder:GetAttribute("Foo") == nil)
|
||||||
|
|
||||||
-- Writing files with modified attributes should work
|
-- Writing files with modified attributes should work
|
||||||
|
|
||||||
local game = Instance.new("DataModel")
|
local game = Instance.new("DataModel")
|
||||||
|
|
Loading…
Reference in a new issue