forked from AllenDang/cimgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_deffiniton.go
83 lines (68 loc) · 2.44 KB
/
function_deffiniton.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/json"
"fmt"
"sort"
)
// FuncDef represents a definition of a function in cimgui's json format
type FuncDef struct {
// FuncName is a cimgui name of the function
FuncName string `json:"ov_cimguiname"`
// FuncName is an original Dear ImGui's name of the function
OriginalFuncName string `json:"original_func_name"`
// Args represents a plain string list of function arguments
Args string `json:"args"`
// ArgsT represents a more accurate list of arg:type list
ArgsT []ArgDef `json:"argsT"`
// Defaults represents a map (arg name : value) of a default C value for
// function's argument
Defaults map[string]string `json:"defaults"`
// Location represents an exact location in DearImGui's source code
Location string `json:"location"`
Constructor bool `json:"constructor"`
Destructor bool `json:"destructor"`
StructSetter bool `json:"struct_setter"`
StructGetter bool `json:"struct_getter"`
InvocationStmt string `json:"invocation_stmt"`
// Ret determines a type of returned value
Ret string `json:"ret"`
StName string `json:"stname"`
// NonUDT is != 0 whenever the function has a pointer argument
// that could be considered as its result.
// e.g. igCalcItemSize takes pOut ImVec2* argument, but it is used
// to store resulting value.
NonUDT int `json:"nonUDT"`
// The names could collide between cimgui and the function generated
// here, so we may need to add a prefix.
CWrapperFuncName string
// AllCallArgs is used to determine if a wrapper is needed: if the cimgui
// function takes the exact same arguments as the wrapper, the wrapper is
// not needed.
AllCallArgs string
}
// ArgDef represents a deffinition of function's argument
type ArgDef struct {
Name string `json:"name"`
Type string `json:"type"`
CustomType string `json:"custom_type"`
}
// getFunDefs takes a json file bytes as an argument and returns
// a list of cimgui functions read.
func getFunDefs(defJsonBytes []byte) ([]FuncDef, error) {
var defJson map[string]json.RawMessage
err := json.Unmarshal(defJsonBytes, &defJson)
if err != nil {
return nil, fmt.Errorf("cannot unmarshal json: %w", err)
}
var funcs []FuncDef
for _, v := range defJson {
var funcDefs []FuncDef
_ = json.Unmarshal(v, &funcDefs)
funcs = append(funcs, funcDefs...)
}
// sort lexicographically for determenistic generation
sort.Slice(funcs, func(i, j int) bool {
return funcs[i].FuncName < funcs[j].FuncName
})
return funcs, nil
}