-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProperties.lua
More file actions
29 lines (27 loc) · 867 Bytes
/
Properties.lua
File metadata and controls
29 lines (27 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---@version 5.2
local metatable = {}
metatable.__newindex = function(prop, key, value)
if type(key) ~= 'string' then
error 'Properties does not support non-string keys'
end
if value == nil then
rawset(prop, key, nil)
return
end
if type(value) ~= 'string' and type(value) ~= 'number' then
error ('Properties does not support non-string value \''..value..'\'')
end
if type(value) == 'number' then
value = tostring(value)
end
rawset(prop, key, value)
end
local Properties = {}
---Returns an empty `Properties` table. This is different from an empty Lua
---table because it verifies that keys and values are strings before they are
---put, and will error out if they aren't.
---@return table properties
Properties.new = function()
return setmetatable({}, metatable)
end
return Properties