forked from SpaiR/imgui-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_to_java.groovy
More file actions
81 lines (67 loc) · 2.2 KB
/
struct_to_java.groovy
File metadata and controls
81 lines (67 loc) · 2.2 KB
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
def inputTxt = new File(args[0]).text
def outputFile = new File(args[1])
def jStructName = args[2] as String
outputFile.text = ''
inputTxt = inputTxt
.replace('ImGuiID', 'int')
.replace('bool', 'boolean')
.replace('char*', 'String')
.replace('const char*', 'String')
def regex = ~'(\\w+)\\s+(\\w+)(?:.*?//(.+))?'
inputTxt.eachLine { line ->
def trimmedLine = line.trim()
if (!trimmedLine.contains(';') || trimmedLine.startsWith('#'))
return
def m = regex.matcher(trimmedLine)
def fieldType
def fieldName
def fieldComment
m.find()
fieldType = m.group(1)
fieldName = m.group(2)
fieldComment = m.group(3)?.trim()
def javadoc = null
if (fieldComment) {
javadoc = """ /**
| * $fieldComment
| */""".stripMargin()
}
def classTxt
if (fieldType == 'ImVec2') {
classTxt = """
|${javadoc ? javadoc : ''}
| public native void get${fieldName.capitalize()}(ImVec2 dstImVec2); /*
| Jni::ImVec2Cpy(env, &$jStructName->$fieldName, dstImVec2);
| */
|
|${javadoc ? javadoc : ''}
| public native float get${fieldName.capitalize()}X(); /*
| return $jStructName->${fieldName}.x;
| */
|
|${javadoc ? javadoc : ''}
| public native float get${fieldName.capitalize()}Y(); /*
| return $jStructName->${fieldName}.y;
| */
|
|${javadoc ? javadoc : ''}
| public native void set${fieldName.capitalize()}(float x, float y); /*
| $jStructName->${fieldName}.x = x;
| $jStructName->${fieldName}.y = y;
| */
""".stripMargin()
} else {
classTxt = """
|${javadoc ? javadoc : ''}
| public native $fieldType get${fieldName.capitalize()}(); /*
| return $jStructName->$fieldName;
| */
|
|${javadoc ? javadoc : ''}
| public native void set${fieldName.capitalize()}($fieldType ${fieldName.uncapitalize()}); /*
| $jStructName->$fieldName = ${fieldName.uncapitalize()};
| */
""".stripMargin()
}
outputFile << classTxt
}