It does not. The most viable solution is transpilation, teal is the most recent candidate.
You can have a hack of sorts using a schema and tables as in
local schema = { a = "number", b="string" } -- key = "type"
local data, link = {a=4, b="default value"}, {} -- link -> data, link itself is always empty
local tbl = setmetatable(link, {
__index = data
, __newindex = function (t,k,v)
if schema[k] and type(v)==schema[k] then data[k] = v return true end
error"type does not match schema"
end
})
tbl.b = 5 -- this will error because its the wrong type
There are certain solutions you can do with functions, lsp is also really good at telling you when you went wrong.
You can have a hack of sorts using a schema and tables as in
local schema = { a = "number", b="string" } -- key = "type" local data, link = {a=4, b="default value"}, {} -- link -> data, link itself is always empty local tbl = setmetatable(link, { __index = data , __newindex = function (t,k,v) if schema[k] and type(v)==schema[k] then data[k] = v return true end error"type does not match schema" end })
tbl.b = 5 -- this will error because its the wrong type
There are certain solutions you can do with functions, lsp is also really good at telling you when you went wrong.