mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Use new rbx_dom_lua API
This commit is contained in:
Submodule plugin/modules/rbx-dom updated: 74ec3e7d88...4b5f8c22c7
@@ -3,30 +3,32 @@ local RbxDom = require(script:FindFirstAncestor("Rojo").RbxDom)
|
|||||||
--[[
|
--[[
|
||||||
Attempts to set a property on the given instance.
|
Attempts to set a property on the given instance.
|
||||||
]]
|
]]
|
||||||
local function setCanonicalProperty(instance, key, value)
|
local function setCanonicalProperty(instance, propertyName, value)
|
||||||
-- If we don't have permissions to access this value at all, we can skip it.
|
local descriptor = RbxDom.findCanonicalPropertyDescriptor(instance.ClassName, propertyName)
|
||||||
local readSuccess, existingValue = RbxDom.readProperty(instance, key)
|
|
||||||
|
|
||||||
if not readSuccess then
|
-- We can skip unknown properties; they're not likely reflected to Lua.
|
||||||
if existingValue.kind == RbxDom.Error.Kind.UnknownProperty
|
--
|
||||||
or existingValue.kind == RbxDom.Error.Kind.PropertyNotReadable then
|
-- A good example of a property like this is `Model.ModelInPrimary`, which
|
||||||
-- this is fine
|
-- is serialized but not reflected to Lua.
|
||||||
return false
|
if descriptor == nil then
|
||||||
end
|
return false, "unknown property"
|
||||||
|
|
||||||
-- If we don't have permission to write a property, we just silently
|
|
||||||
-- ignore it.
|
|
||||||
if existingValue.kind == RbxDom.Error.Kind.Roblox and existingValue.extra:find("lacking permission") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, tostring(existingValue)), 2)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local writeSuccess, err = RbxDom.writeProperty(instance, key, value)
|
if descriptor.scriptability == "None" or descriptor.scriptability == "Read" then
|
||||||
|
return false, "unwritable property"
|
||||||
|
end
|
||||||
|
|
||||||
if not writeSuccess then
|
local success, err = descriptor:write(instance, value)
|
||||||
error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, tostring(err)), 2)
|
|
||||||
|
if not success then
|
||||||
|
-- If we don't have permission to write a property, we just silently
|
||||||
|
-- ignore it.
|
||||||
|
if err.kind == RbxDom.Error.Kind.Roblox and err.extra:find("lacking permission") then
|
||||||
|
return false, "permission error"
|
||||||
|
end
|
||||||
|
|
||||||
|
local message = ("Invalid property %s.%s: %s"):format(descriptor.className, descriptor.name, tostring(err))
|
||||||
|
error(message, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user