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
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

View File

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