Skip to content

Commit 070d88b

Browse files
committed
Cache StringNames used for Properties, Methods and Signals
1 parent 7938468 commit 070d88b

File tree

14 files changed

+420
-163
lines changed

14 files changed

+420
-163
lines changed

GDExtensionBindgen/LuaCoroutine.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace GDExtensionBindgen;
77

88
public class LuaCoroutine : LuaObject
99
{
10-
public new static readonly StringName ClassName = "LuaCoroutine";
11-
12-
public LuaCoroutine() : base(ClassName)
10+
public LuaCoroutine() : base(NativeName)
1311
{
1412
}
1513
protected LuaCoroutine(StringName @class) : base(@class)
@@ -26,6 +24,26 @@ protected LuaCoroutine([NotNull] RefCounted @object) : base(@object)
2624
public static implicit operator Variant(LuaCoroutine self) => self?._object;
2725
public static explicit operator LuaCoroutine(Variant variant) => variant.AsGodotObject() != null ? new(variant) : null;
2826

27+
public new class PropertyName : LuaObject.PropertyName
28+
{
29+
public static readonly StringName Status = "status";
30+
}
31+
32+
public new class MethodName : LuaObject.MethodName
33+
{
34+
public static readonly StringName GetStatus = "get_status";
35+
public static readonly StringName Resumev = "resumev";
36+
public static readonly StringName Resume = "resume";
37+
public static readonly StringName Create = "create";
38+
}
39+
40+
public new class SignalName : LuaObject.SignalName
41+
{
42+
43+
}
44+
45+
private static readonly StringName NativeName = "LuaCoroutine";
46+
2947
#region Enums
3048

3149
public enum LuaCoroutineStatusEnum
@@ -45,7 +63,7 @@ public enum LuaCoroutineStatusEnum
4563

4664
public int Status
4765
{
48-
get => (int)_object.Get("status");
66+
get => (int)_object.Get(PropertyName.Status);
4967
}
5068

5169
#endregion
@@ -54,22 +72,22 @@ public int Status
5472

5573
public LuaCoroutine.LuaCoroutineStatusEnum GetStatus()
5674
{
57-
return (LuaCoroutine.LuaCoroutineStatusEnum)(int)_object.Call("get_status");
75+
return (LuaCoroutine.LuaCoroutineStatusEnum)(int)_object.Call(MethodName.GetStatus);
5876
}
5977

6078
public Variant Resumev(Godot.Collections.Array @arguments)
6179
{
62-
return (Variant)_object.Call("resumev", @arguments);
80+
return (Variant)_object.Call(MethodName.Resumev, @arguments);
6381
}
6482

6583
public Variant Resume(params Variant[] varargs)
6684
{
67-
return (Variant)_object.Call("resume", varargs);
85+
return (Variant)_object.Call(MethodName.Resume, varargs);
6886
}
6987

7088
public static LuaCoroutine Create(LuaFunction @function)
7189
{
72-
return (LuaCoroutine)ClassDB.ClassCallStatic(ClassName, "create", @function);
90+
return (LuaCoroutine)ClassDB.ClassCallStatic(NativeName, MethodName.Create, @function);
7391
}
7492

7593
#endregion

GDExtensionBindgen/LuaError.cs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ namespace GDExtensionBindgen;
77

88
public class LuaError
99
{
10-
public static readonly StringName ClassName = "LuaError";
11-
10+
// Engine object used for calling engine methods
1211
protected RefCounted _object;
1312

14-
public LuaError() : this(ClassName)
13+
public LuaError() : this(NativeName)
1514
{
1615
}
1716
protected LuaError(StringName @class) : this(ClassDB.Instantiate(@class))
@@ -29,6 +28,27 @@ protected LuaError([NotNull] RefCounted @object)
2928
public static implicit operator Variant(LuaError self) => self?._object;
3029
public static explicit operator LuaError(Variant variant) => variant.AsGodotObject() != null ? new(variant) : null;
3130

31+
public class PropertyName : RefCounted.PropertyName
32+
{
33+
public static readonly StringName Message = "message";
34+
public static readonly StringName Status = "status";
35+
}
36+
37+
public class MethodName : RefCounted.MethodName
38+
{
39+
public static readonly StringName GetMessage = "get_message";
40+
public static readonly StringName SetMessage = "set_message";
41+
public static readonly StringName GetStatus = "get_status";
42+
public static readonly StringName SetStatus = "set_status";
43+
}
44+
45+
public class SignalName : RefCounted.SignalName
46+
{
47+
48+
}
49+
50+
private static readonly StringName NativeName = "LuaError";
51+
3252
#region Enums
3353

3454
public enum StatusEnum
@@ -49,14 +69,14 @@ public enum StatusEnum
4969

5070
public string Message
5171
{
52-
get => (string)_object.Get("message");
53-
set => _object.Set("message", value);
72+
get => (string)_object.Get(PropertyName.Message);
73+
set => _object.Set(PropertyName.Message, value);
5474
}
5575

5676
public string Status
5777
{
58-
get => (string)_object.Get("status");
59-
set => _object.Set("status", value);
78+
get => (string)_object.Get(PropertyName.Status);
79+
set => _object.Set(PropertyName.Status, value);
6080
}
6181

6282
#endregion
@@ -65,22 +85,22 @@ public string Status
6585

6686
public string GetMessage()
6787
{
68-
return (string)_object.Call("get_message");
88+
return (string)_object.Call(MethodName.GetMessage);
6989
}
7090

7191
public void SetMessage(string @message)
7292
{
73-
_object.Call("set_message", @message);
93+
_object.Call(MethodName.SetMessage, @message);
7494
}
7595

7696
public LuaError.StatusEnum GetStatus()
7797
{
78-
return (LuaError.StatusEnum)(int)_object.Call("get_status");
98+
return (LuaError.StatusEnum)(int)_object.Call(MethodName.GetStatus);
7999
}
80100

81101
public void SetStatus(LuaError.StatusEnum @status)
82102
{
83-
_object.Call("set_status", (int)@status);
103+
_object.Call(MethodName.SetStatus, (int)@status);
84104
}
85105

86106
#endregion
@@ -368,23 +388,23 @@ public event Action ScriptChanged
368388
{
369389
add
370390
{
371-
Connect("script_changed", Callable.From(value));
391+
Connect(SignalName.ScriptChanged, Callable.From(value));
372392
}
373393
remove
374394
{
375-
Disconnect("script_changed", Callable.From(value));
395+
Disconnect(SignalName.ScriptChanged, Callable.From(value));
376396
}
377397
}
378398

379399
public event Action PropertyListChanged
380400
{
381401
add
382402
{
383-
Connect("property_list_changed", Callable.From(value));
403+
Connect(SignalName.PropertyListChanged, Callable.From(value));
384404
}
385405
remove
386406
{
387-
Disconnect("property_list_changed", Callable.From(value));
407+
Disconnect(SignalName.PropertyListChanged, Callable.From(value));
388408
}
389409
}
390410

GDExtensionBindgen/LuaFunction.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace GDExtensionBindgen;
77

88
public class LuaFunction : LuaObject
99
{
10-
public new static readonly StringName ClassName = "LuaFunction";
11-
12-
public LuaFunction() : base(ClassName)
10+
public LuaFunction() : base(NativeName)
1311
{
1412
}
1513
protected LuaFunction(StringName @class) : base(@class)
@@ -26,21 +24,40 @@ protected LuaFunction([NotNull] RefCounted @object) : base(@object)
2624
public static implicit operator Variant(LuaFunction self) => self?._object;
2725
public static explicit operator LuaFunction(Variant variant) => variant.AsGodotObject() != null ? new(variant) : null;
2826

27+
public new class PropertyName : LuaObject.PropertyName
28+
{
29+
30+
}
31+
32+
public new class MethodName : LuaObject.MethodName
33+
{
34+
public static readonly StringName Invokev = "invokev";
35+
public static readonly StringName Invoke = "invoke";
36+
public static readonly StringName ToCallable = "to_callable";
37+
}
38+
39+
public new class SignalName : LuaObject.SignalName
40+
{
41+
42+
}
43+
44+
private static readonly StringName NativeName = "LuaFunction";
45+
2946
#region Methods
3047

3148
public Variant Invokev(Godot.Collections.Array @arg_array)
3249
{
33-
return (Variant)_object.Call("invokev", @arg_array);
50+
return (Variant)_object.Call(MethodName.Invokev, @arg_array);
3451
}
3552

3653
public Variant Invoke(params Variant[] varargs)
3754
{
38-
return (Variant)_object.Call("invoke", varargs);
55+
return (Variant)_object.Call(MethodName.Invoke, varargs);
3956
}
4057

4158
public Godot.Callable ToCallable()
4259
{
43-
return (Godot.Callable)_object.Call("to_callable");
60+
return (Godot.Callable)_object.Call(MethodName.ToCallable);
4461
}
4562

4663
#endregion

GDExtensionBindgen/LuaLightUserdata.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace GDExtensionBindgen;
77

88
public class LuaLightUserdata : LuaObject
99
{
10-
public new static readonly StringName ClassName = "LuaLightUserdata";
11-
12-
public LuaLightUserdata() : base(ClassName)
10+
public LuaLightUserdata() : base(NativeName)
1311
{
1412
}
1513
protected LuaLightUserdata(StringName @class) : base(@class)
@@ -25,4 +23,21 @@ protected LuaLightUserdata([NotNull] RefCounted @object) : base(@object)
2523
public static implicit operator RefCounted(LuaLightUserdata self) => self?._object;
2624
public static implicit operator Variant(LuaLightUserdata self) => self?._object;
2725
public static explicit operator LuaLightUserdata(Variant variant) => variant.AsGodotObject() != null ? new(variant) : null;
26+
27+
public new class PropertyName : LuaObject.PropertyName
28+
{
29+
30+
}
31+
32+
public new class MethodName : LuaObject.MethodName
33+
{
34+
35+
}
36+
37+
public new class SignalName : LuaObject.SignalName
38+
{
39+
40+
}
41+
42+
private static readonly StringName NativeName = "LuaLightUserdata";
2843
}

GDExtensionBindgen/LuaObject.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ namespace GDExtensionBindgen;
77

88
public class LuaObject
99
{
10-
public static readonly StringName ClassName = "LuaObject";
11-
10+
// Engine object used for calling engine methods
1211
protected RefCounted _object;
1312

14-
public LuaObject() : this(ClassName)
13+
public LuaObject() : this(NativeName)
1514
{
1615
}
1716
protected LuaObject(StringName @class) : this(ClassDB.Instantiate(@class))
@@ -29,16 +28,34 @@ protected LuaObject([NotNull] RefCounted @object)
2928
public static implicit operator Variant(LuaObject self) => self?._object;
3029
public static explicit operator LuaObject(Variant variant) => variant.AsGodotObject() != null ? new(variant) : null;
3130

31+
public class PropertyName : RefCounted.PropertyName
32+
{
33+
34+
}
35+
36+
public class MethodName : RefCounted.MethodName
37+
{
38+
public static readonly StringName GetLuaState = "get_lua_state";
39+
public static readonly StringName GetPointerValue = "get_pointer_value";
40+
}
41+
42+
public class SignalName : RefCounted.SignalName
43+
{
44+
45+
}
46+
47+
private static readonly StringName NativeName = "LuaObject";
48+
3249
#region Methods
3350

3451
public LuaState GetLuaState()
3552
{
36-
return (LuaState)_object.Call("get_lua_state");
53+
return (LuaState)_object.Call(MethodName.GetLuaState);
3754
}
3855

3956
public int GetPointerValue()
4057
{
41-
return (int)_object.Call("get_pointer_value");
58+
return (int)_object.Call(MethodName.GetPointerValue);
4259
}
4360

4461
#endregion
@@ -326,23 +343,23 @@ public event Action ScriptChanged
326343
{
327344
add
328345
{
329-
Connect("script_changed", Callable.From(value));
346+
Connect(SignalName.ScriptChanged, Callable.From(value));
330347
}
331348
remove
332349
{
333-
Disconnect("script_changed", Callable.From(value));
350+
Disconnect(SignalName.ScriptChanged, Callable.From(value));
334351
}
335352
}
336353

337354
public event Action PropertyListChanged
338355
{
339356
add
340357
{
341-
Connect("property_list_changed", Callable.From(value));
358+
Connect(SignalName.PropertyListChanged, Callable.From(value));
342359
}
343360
remove
344361
{
345-
Disconnect("property_list_changed", Callable.From(value));
362+
Disconnect(SignalName.PropertyListChanged, Callable.From(value));
346363
}
347364
}
348365

0 commit comments

Comments
 (0)