57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type (
|
|
Class struct {
|
|
ClassName string
|
|
Fields []Field
|
|
Methods []Method
|
|
Constructors []Constructor
|
|
}
|
|
Field struct {
|
|
Name string
|
|
Type string
|
|
Comment string
|
|
}
|
|
Method struct {
|
|
Name string
|
|
Params []Param
|
|
Returns []Return
|
|
Comment string
|
|
}
|
|
Param struct {
|
|
Name string
|
|
Type string
|
|
Comment string
|
|
}
|
|
Return struct {
|
|
Type string
|
|
Comment string
|
|
}
|
|
Constructor struct {
|
|
Params []Param
|
|
Comment string
|
|
}
|
|
)
|
|
|
|
func (c *Class) GetOutFile() (*os.File, error) {
|
|
if c.ClassName == "" {
|
|
return nil, fmt.Errorf("ClassName is empty")
|
|
}
|
|
filename := fmt.Sprintf("%s.lua", c.ClassName)
|
|
filename = strings.ReplaceAll(filename, " ", "")
|
|
filename = strings.ReplaceAll(filename, "-", "")
|
|
filename = strings.ReplaceAll(filename, ",", "")
|
|
filename = strings.ReplaceAll(filename, ":", "")
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f, nil
|
|
}
|