mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Switch to userdata with locked metatable
This commit is contained in:
parent
1cd215359d
commit
ab75e2b549
1 changed files with 31 additions and 30 deletions
|
|
@ -413,8 +413,9 @@ function API.new(app)
|
|||
return ApiContext.new(baseUrl)
|
||||
end
|
||||
|
||||
local ReadOnly = setmetatable({}, {
|
||||
__index = function(_, key)
|
||||
local ReadOnly = newproxy(true)
|
||||
local Metatable = getmetatable(ReadOnly)
|
||||
Metatable.__index = function(_, key)
|
||||
-- Don't expose private members
|
||||
if string.find(key, "^_") then
|
||||
return nil
|
||||
|
|
@ -440,12 +441,12 @@ function API.new(app)
|
|||
end
|
||||
|
||||
return Rojo[key]
|
||||
end,
|
||||
__newindex = function(_, key, value)
|
||||
end
|
||||
Metatable.__newindex = function(_, key, value)
|
||||
error(string.format("Attempted to set Rojo.%s to %q but it's a read-only value", key, value), 2)
|
||||
return
|
||||
end,
|
||||
})
|
||||
end
|
||||
Metatable.__metatable = "The metatable of the Rojo API is locked"
|
||||
|
||||
return Rojo, ReadOnly
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue