diff --git a/function.tmpl b/function.tmpl new file mode 100644 index 0000000..f9725e3 --- /dev/null +++ b/function.tmpl @@ -0,0 +1,2 @@ +---@diagnostic disable: missing-return, lowercase-global +function {{.Name}}({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}) end \ No newline at end of file diff --git a/types.go b/types.go index bd87360..842cddb 100644 --- a/types.go +++ b/types.go @@ -1,13 +1,58 @@ package main +import ( + _ "embed" + "log" + "os" + "text/template" +) + +var fns = template.FuncMap{ + "plus1": func(x int) int { + return x + 1 + }, +} + +//go:embed function.tmpl +var templatestr string + +var functionTemplate *template.Template +func init() { + var err error + functionTemplate, err = template.New("class").Funcs(fns).Parse(templatestr) + if err != nil { + Error.Printf("Error parsing template: %v", err) + return + } + log.Printf("%#v", functionTemplate) +} + type ( Function struct { + Name string Arguments []Argument Returns []Argument } Argument struct { - Name string - Type string + Name string + Type string Description string } -) \ No newline at end of file +) + +func (f *Function) ResolveFileName() string { + return f.Name + ".lua" +} +func (f *Function) WriteFile() error { + file, err := os.Create(f.ResolveFileName()) + if err != nil { + return err + } + defer file.Close() + + err = functionTemplate.Execute(file, f) + if err != nil { + return err + } + return nil +} \ No newline at end of file