Skip to content

Commit

Permalink
Form: deferred formspec parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
S-S-X committed Jan 13, 2025
1 parent 034914f commit 3cff970
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions formspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ function Form:version()
error("Not implemented: Form:version()")
end

function Form:__index(key)
local value = rawget(Form, key)
if value ~= nil then
return value
end
value = rawget(self, key)
if value ~= nil then
return value
elseif key == "_data" then
rawset(self, "_data", parse(rawget(self, "_textcontent")))
return rawget(self, "_data")
end
end

function Form:__tostring()
return self._textcontent
end
Expand Down Expand Up @@ -359,8 +373,7 @@ mineunit.export_object(Form, {
local obj = {
_name = formname,
_version = nil,
-- TODO: determine if deferred parse makes any sense
_data = parse(formspec),
_data = nil, -- deferrend _textcontent parsing
_textcontent = formspec,
}
setmetatable(obj, Form)
Expand Down

0 comments on commit 3cff970

Please sign in to comment.