forked from mangalorg/gopher-luadoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.go
52 lines (43 loc) · 807 Bytes
/
func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package luadoc
import (
"strings"
lua "github.com/yuin/gopher-lua"
)
type Param struct {
Name string
Description string
Type string
Optional bool
}
func (p *Param) String() string {
return p.Name
}
type Func struct {
Name string
Description string
Value lua.LGFunction
Generics []string
Params []*Param
Returns []*Param
}
func (f Func) AsType() string {
var b strings.Builder
b.WriteString("fun(")
for i, param := range f.Params {
b.WriteString(param.Name)
b.WriteString(": ")
b.WriteString(param.Type)
if param.Optional {
b.WriteString("?")
}
if i < len(f.Params)-1 {
b.WriteString(", ")
}
}
b.WriteString(")")
if len(f.Returns) > 0 {
b.WriteString(": ")
b.WriteString(f.Returns[0].Type)
}
return b.String()
}