mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 21:41:37 +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)
|
return ApiContext.new(baseUrl)
|
||||||
end
|
end
|
||||||
|
|
||||||
local ReadOnly = setmetatable({}, {
|
local ReadOnly = newproxy(true)
|
||||||
__index = function(_, key)
|
local Metatable = getmetatable(ReadOnly)
|
||||||
|
Metatable.__index = function(_, key)
|
||||||
-- Don't expose private members
|
-- Don't expose private members
|
||||||
if string.find(key, "^_") then
|
if string.find(key, "^_") then
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -440,12 +441,12 @@ function API.new(app)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Rojo[key]
|
return Rojo[key]
|
||||||
end,
|
end
|
||||||
__newindex = function(_, key, value)
|
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)
|
error(string.format("Attempted to set Rojo.%s to %q but it's a read-only value", key, value), 2)
|
||||||
return
|
return
|
||||||
end,
|
end
|
||||||
})
|
Metatable.__metatable = "The metatable of the Rojo API is locked"
|
||||||
|
|
||||||
return Rojo, ReadOnly
|
return Rojo, ReadOnly
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue