Skip to content

Commit b9169b3

Browse files
committed
Add support for integer constants
1 parent 621fd67 commit b9169b3

File tree

9 files changed

+229
-3
lines changed

9 files changed

+229
-3
lines changed

GDExtensionBindgen/LuaError.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ public enum StatusEnum : long
6565

6666
#endregion
6767

68+
#region Inherited Integer Constants
69+
70+
public const long NotificationPostinitialize = 0L;
71+
72+
public const long NotificationPredelete = 1L;
73+
74+
public const long NotificationExtensionReloaded = 2L;
75+
76+
public const long ConnectDeferred = 1L;
77+
78+
public const long ConnectPersist = 2L;
79+
80+
public const long ConnectOneShot = 4L;
81+
82+
public const long ConnectReferenceCounted = 8L;
83+
84+
#endregion
85+
6886
#region Properties
6987

7088
public string Message

GDExtensionBindgen/LuaObject.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ public class SignalName : RefCounted.SignalName
4646

4747
private static readonly StringName NativeName = "LuaObject";
4848

49+
#region Inherited Integer Constants
50+
51+
public const long NotificationPostinitialize = 0L;
52+
53+
public const long NotificationPredelete = 1L;
54+
55+
public const long NotificationExtensionReloaded = 2L;
56+
57+
public const long ConnectDeferred = 1L;
58+
59+
public const long ConnectPersist = 2L;
60+
61+
public const long ConnectOneShot = 4L;
62+
63+
public const long ConnectReferenceCounted = 8L;
64+
65+
#endregion
66+
4967
#region Methods
5068

5169
public LuaState GetLuaState()

GDExtensionBindgen/LuaScript.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public class SignalName : ScriptExtension.SignalName
4545

4646
private static readonly StringName NativeName = "LuaScript";
4747

48+
#region Inherited Integer Constants
49+
50+
public const long NotificationPostinitialize = 0L;
51+
52+
public const long NotificationPredelete = 1L;
53+
54+
public const long NotificationExtensionReloaded = 2L;
55+
56+
public const long ConnectDeferred = 1L;
57+
58+
public const long ConnectPersist = 2L;
59+
60+
public const long ConnectOneShot = 4L;
61+
62+
public const long ConnectReferenceCounted = 8L;
63+
64+
#endregion
65+
4866
#region Inherited Properties
4967

5068
public string SourceCode

GDExtensionBindgen/LuaScriptLanguage.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,86 @@ public class SignalName : ScriptLanguageExtension.SignalName
4545

4646
private static readonly StringName NativeName = "LuaScriptLanguage";
4747

48+
#region Inherited Integer Constants
49+
50+
public const long LookupResultScriptLocation = 0L;
51+
52+
public const long LookupResultClass = 1L;
53+
54+
public const long LookupResultClassConstant = 2L;
55+
56+
public const long LookupResultClassProperty = 3L;
57+
58+
public const long LookupResultClassMethod = 4L;
59+
60+
public const long LookupResultClassSignal = 5L;
61+
62+
public const long LookupResultClassEnum = 6L;
63+
64+
public const long LookupResultClassTbdGlobalscope = 7L;
65+
66+
public const long LookupResultClassAnnotation = 8L;
67+
68+
public const long LookupResultLocalConstant = 9L;
69+
70+
public const long LookupResultLocalVariable = 10L;
71+
72+
public const long LookupResultMax = 11L;
73+
74+
public const long LocationLocal = 0L;
75+
76+
public const long LocationParentMask = 256L;
77+
78+
public const long LocationOtherUserCode = 512L;
79+
80+
public const long LocationOther = 1024L;
81+
82+
public const long CodeCompletionKindClass = 0L;
83+
84+
public const long CodeCompletionKindFunction = 1L;
85+
86+
public const long CodeCompletionKindSignal = 2L;
87+
88+
public const long CodeCompletionKindVariable = 3L;
89+
90+
public const long CodeCompletionKindMember = 4L;
91+
92+
public const long CodeCompletionKindEnum = 5L;
93+
94+
public const long CodeCompletionKindConstant = 6L;
95+
96+
public const long CodeCompletionKindNodePath = 7L;
97+
98+
public const long CodeCompletionKindFilePath = 8L;
99+
100+
public const long CodeCompletionKindPlainText = 9L;
101+
102+
public const long CodeCompletionKindMax = 10L;
103+
104+
public const long ScriptNameCasingAuto = 0L;
105+
106+
public const long ScriptNameCasingPascalCase = 1L;
107+
108+
public const long ScriptNameCasingSnakeCase = 2L;
109+
110+
public const long ScriptNameCasingKebabCase = 3L;
111+
112+
public const long NotificationPostinitialize = 0L;
113+
114+
public const long NotificationPredelete = 1L;
115+
116+
public const long NotificationExtensionReloaded = 2L;
117+
118+
public const long ConnectDeferred = 1L;
119+
120+
public const long ConnectPersist = 2L;
121+
122+
public const long ConnectOneShot = 4L;
123+
124+
public const long ConnectReferenceCounted = 8L;
125+
126+
#endregion
127+
48128
#region Inherited Methods
49129

50130
public void Free()

GDExtensionBindgen/LuaScriptResourceFormatLoader.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ public class SignalName : ResourceFormatLoader.SignalName
4545

4646
private static readonly StringName NativeName = "LuaScriptResourceFormatLoader";
4747

48+
#region Inherited Integer Constants
49+
50+
public const long CacheModeIgnore = 0L;
51+
52+
public const long CacheModeReuse = 1L;
53+
54+
public const long CacheModeReplace = 2L;
55+
56+
public const long CacheModeIgnoreDeep = 3L;
57+
58+
public const long CacheModeReplaceDeep = 4L;
59+
60+
public const long NotificationPostinitialize = 0L;
61+
62+
public const long NotificationPredelete = 1L;
63+
64+
public const long NotificationExtensionReloaded = 2L;
65+
66+
public const long ConnectDeferred = 1L;
67+
68+
public const long ConnectPersist = 2L;
69+
70+
public const long ConnectOneShot = 4L;
71+
72+
public const long ConnectReferenceCounted = 8L;
73+
74+
#endregion
75+
4876
#region Inherited Methods
4977

5078
public bool InitRef()

GDExtensionBindgen/LuaScriptResourceFormatSaver.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public class SignalName : ResourceFormatSaver.SignalName
4545

4646
private static readonly StringName NativeName = "LuaScriptResourceFormatSaver";
4747

48+
#region Inherited Integer Constants
49+
50+
public const long NotificationPostinitialize = 0L;
51+
52+
public const long NotificationPredelete = 1L;
53+
54+
public const long NotificationExtensionReloaded = 2L;
55+
56+
public const long ConnectDeferred = 1L;
57+
58+
public const long ConnectPersist = 2L;
59+
60+
public const long ConnectOneShot = 4L;
61+
62+
public const long ConnectReferenceCounted = 8L;
63+
64+
#endregion
65+
4866
#region Inherited Methods
4967

5068
public bool InitRef()

GDExtensionBindgen/LuaState.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ public enum LibraryEnum : long
8282

8383
#endregion
8484

85+
#region Inherited Integer Constants
86+
87+
public const long NotificationPostinitialize = 0L;
88+
89+
public const long NotificationPredelete = 1L;
90+
91+
public const long NotificationExtensionReloaded = 2L;
92+
93+
public const long ConnectDeferred = 1L;
94+
95+
public const long ConnectPersist = 2L;
96+
97+
public const long ConnectOneShot = 4L;
98+
99+
public const long ConnectReferenceCounted = 8L;
100+
101+
#endregion
102+
85103
#region Properties
86104

87105
public LuaTable Globals

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WIP C# bindings generator for GDExtension classes
1010

1111

1212
## TODO
13-
- [ ] support constant integers that are not part of any enum
13+
- [X] support constant integers that are not part of any enum
1414
- [X] get/set properties inherited from engine class directly without Get/Set
1515
- [X] support signals
1616
- [ ] submit to the Asset Library

addons/csharp_gdextension_bindgen/csharp_gdextension_bindgen.gd

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
##
66
## Use the "Project -> Tools -> Generate C# GDExtension Bindings" menu item to
77
## generate C# bindings from GDExtension.
8-
##
9-
## TODO: support constant integers that are not part of any enum
108
@tool
119
extends EditorPlugin
1210

@@ -101,6 +99,21 @@ func generate_csharp_script(cls_name: StringName):
10199
var enums = PackedStringArray()
102100
for enum_name in ClassDB.class_get_enum_list(cls_name, true):
103101
enums.append(_generate_enum(cls_name, enum_name))
102+
103+
# INTEGER CONSTANTS
104+
var integer_constants = PackedStringArray()
105+
for constant_name in ClassDB.class_get_integer_constant_list(cls_name, true):
106+
if not ClassDB.class_get_integer_constant_enum(cls_name, constant_name, true).is_empty():
107+
continue
108+
integer_constants.append(_generate_integer_constant(cls_name, constant_name))
109+
110+
var inherited_integer_constants = PackedStringArray()
111+
if not parent_class_is_extension:
112+
for inherited_class in _get_parent_classes(cls_name):
113+
for constant_name in ClassDB.class_get_integer_constant_list(inherited_class, true):
114+
if not ClassDB.class_get_integer_constant_enum(cls_name, constant_name, true).is_empty():
115+
continue
116+
inherited_integer_constants.append(_generate_integer_constant(inherited_class, constant_name))
104117

105118
# PROPERTIES
106119
var properties = PackedStringArray()
@@ -161,6 +174,14 @@ func generate_csharp_script(cls_name: StringName):
161174
regions.append("#region Enums")
162175
regions.append("\n\n".join(enums))
163176
regions.append("#endregion")
177+
if not integer_constants.is_empty():
178+
regions.append("#region Integer Constants")
179+
regions.append("\n\n".join(integer_constants))
180+
regions.append("#endregion")
181+
if not inherited_integer_constants.is_empty():
182+
regions.append("#region Inherited Integer Constants")
183+
regions.append("\n\n".join(inherited_integer_constants))
184+
regions.append("#endregion")
164185
if not properties.is_empty():
165186
regions.append("#region Properties")
166187
regions.append("\n\n".join(properties))
@@ -249,6 +270,13 @@ static func _generate_enum(cls_name: StringName, enum_name: StringName) -> Strin
249270
}).strip_edges()
250271

251272

273+
static func _generate_integer_constant(cls_name: StringName, constant_name: StringName) -> String:
274+
return "public const long {csharp_constant_name} = {constant_value}L;".format({
275+
csharp_constant_name = constant_name.to_pascal_case(),
276+
constant_value = ClassDB.class_get_integer_constant(cls_name, constant_name),
277+
})
278+
279+
252280
static func _generate_property(cls_name: StringName, property: Dictionary) -> String:
253281
var property_name = property["name"]
254282
var csharp_property_name = property_name.to_pascal_case()

0 commit comments

Comments
 (0)