Implement module section types "Signals" (#18) #23

Merged
Aire-One merged 5 commits from feat/#18 into master 2022-10-23 21:39:59 +02:00
2 changed files with 21 additions and 7 deletions
Showing only changes of commit 8cc37b127b - Show all commits

View File

@ -44,4 +44,22 @@ function snippets.render_record_functions(items: List<Function_Info.Function_Inf
end):concat("\n") end):concat("\n")
end end
function snippets.render_enum(name: string, values: List<string>): string
local tmpl = [[
enum $(name)
$(indent(body))
end
]]
local tmpl_args = {
name = name,
body = values:map(function(value: string): string
return string.format('"%s"', value)
end):concat("\n"),
indent = snippets.indent,
}
return utils.do_or_fail(template.substitute, tmpl, tmpl_args)
end
return snippets return snippets

View File

@ -8,15 +8,11 @@ local snippets = require "generator.snippets"
local tmpl = [[ local tmpl = [[
-- Auto generated file (Do not manually edit this file!) -- Auto generated file (Do not manually edit this file!)
# if module.signals then local record $(mod_name)
local enum signals # if #module.signals then
# for _, signal in ipairs(module.signals) do $(snippets.indent(snippets.render_enum("Signal", module.signals)))
"$(signal.name)"
# end
end
# end -- /signals # end -- /signals
local record $(mod_name)
# if #module.methods then # if #module.methods then
-- Object methods -- Object methods
$(snippets.indent(snippets.render_record_functions(module.methods))) $(snippets.indent(snippets.render_record_functions(module.methods)))