mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Fix unnecessary error message printing for destroyed instances
This commit is contained in:
parent
580ed6414c
commit
6895b66550
3 changed files with 47 additions and 5 deletions
|
@ -8,6 +8,13 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed accessing a destroyed instance printing an error message even if placed inside a pcall
|
||||
- Fixed cloned instances not having correct instance reference properties set (`ObjectValue.Value`, `Motor6D.Part0`, ...)
|
||||
|
||||
## `0.6.2` - March 25th, 2023
|
||||
|
||||
This release adds some new features and fixes for the `roblox` built-in.
|
||||
|
|
|
@ -250,10 +250,9 @@ impl Instance {
|
|||
|
||||
fn ensure_not_destroyed(&self) -> LuaResult<()> {
|
||||
if self.is_destroyed() {
|
||||
Err(LuaError::RuntimeError(format!(
|
||||
"Tried to access destroyed instance '{}'",
|
||||
self
|
||||
)))
|
||||
Err(LuaError::RuntimeError(
|
||||
"Instance has been destroyed".to_string(),
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -704,7 +703,10 @@ impl Instance {
|
|||
|
||||
impl LuaUserData for Instance {
|
||||
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||
methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string);
|
||||
methods.add_meta_method(LuaMetaMethod::ToString, |lua, this, ()| {
|
||||
this.ensure_not_destroyed()?;
|
||||
userdata_impl_to_string(lua, this, ())
|
||||
});
|
||||
methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq);
|
||||
/*
|
||||
Getting a value does the following:
|
||||
|
|
33
tests/roblox/instance/methods/ClearAllChildren.luau
Normal file
33
tests/roblox/instance/methods/ClearAllChildren.luau
Normal file
|
@ -0,0 +1,33 @@
|
|||
local roblox = require("@lune/roblox") :: any
|
||||
local Instance = roblox.Instance
|
||||
|
||||
local root = Instance.new("Model")
|
||||
local child1 = Instance.new("Part")
|
||||
local child2 = Instance.new("Part")
|
||||
|
||||
child1.Parent = root
|
||||
child2.Parent = root
|
||||
|
||||
assert(#root:GetChildren() == 2)
|
||||
assert(root:GetChildren()[1] == child1)
|
||||
assert(root:GetChildren()[2] == child2)
|
||||
|
||||
root:ClearAllChildren()
|
||||
|
||||
assert(#root:GetChildren() == 0)
|
||||
|
||||
assert(not pcall(function()
|
||||
return child1.Name
|
||||
end))
|
||||
|
||||
assert(not pcall(function()
|
||||
return child1.Parent
|
||||
end))
|
||||
|
||||
assert(not pcall(function()
|
||||
return child2.Name
|
||||
end))
|
||||
|
||||
assert(not pcall(function()
|
||||
return child2.Parent
|
||||
end))
|
Loading…
Reference in a new issue