You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Merge pull request #81783 from zaevi/fix-csharp-static-method
C#: make C# static methods accessible.
This commit is contained in:
@@ -29,6 +29,7 @@ namespace Godot.Bridge
|
||||
public delegate* unmanaged<IntPtr, IntPtr*, godot_bool, godot_bool> ScriptManagerBridge_SwapGCHandleForType;
|
||||
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, godot_string*, void*, int, void>, void> ScriptManagerBridge_GetPropertyInfoList;
|
||||
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, void*, int, void>, void> ScriptManagerBridge_GetPropertyDefaultValues;
|
||||
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant**, int, godot_variant_call_error*, godot_variant*, godot_bool> ScriptManagerBridge_CallStatic;
|
||||
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant**, int, godot_variant_call_error*, godot_variant*, godot_bool> CSharpInstanceBridge_Call;
|
||||
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant*, godot_bool> CSharpInstanceBridge_Set;
|
||||
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant*, godot_bool> CSharpInstanceBridge_Get;
|
||||
@@ -70,6 +71,7 @@ namespace Godot.Bridge
|
||||
ScriptManagerBridge_SwapGCHandleForType = &ScriptManagerBridge.SwapGCHandleForType,
|
||||
ScriptManagerBridge_GetPropertyInfoList = &ScriptManagerBridge.GetPropertyInfoList,
|
||||
ScriptManagerBridge_GetPropertyDefaultValues = &ScriptManagerBridge.GetPropertyDefaultValues,
|
||||
ScriptManagerBridge_CallStatic = &ScriptManagerBridge.CallStatic,
|
||||
CSharpInstanceBridge_Call = &CSharpInstanceBridge.Call,
|
||||
CSharpInstanceBridge_Set = &CSharpInstanceBridge.Set,
|
||||
CSharpInstanceBridge_Get = &CSharpInstanceBridge.Get,
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Godot.Bridge
|
||||
internal static unsafe IntPtr CreateManagedForGodotObjectBinding(godot_string_name* nativeTypeName,
|
||||
IntPtr godotObject)
|
||||
{
|
||||
// TODO: Optimize with source generators and delegate pointers
|
||||
// TODO: Optimize with source generators and delegate pointers.
|
||||
|
||||
try
|
||||
{
|
||||
@@ -124,7 +124,7 @@ namespace Godot.Bridge
|
||||
IntPtr godotObject,
|
||||
godot_variant** args, int argCount)
|
||||
{
|
||||
// TODO: Optimize with source generators and delegate pointers
|
||||
// TODO: Optimize with source generators and delegate pointers.
|
||||
|
||||
try
|
||||
{
|
||||
@@ -677,6 +677,8 @@ namespace Godot.Bridge
|
||||
|
||||
methodInfo.Add("params", methodParams);
|
||||
|
||||
methodInfo.Add("flags", (int)method.Flags);
|
||||
|
||||
methods.Add(methodInfo);
|
||||
}
|
||||
}
|
||||
@@ -958,6 +960,54 @@ namespace Godot.Bridge
|
||||
public godot_variant Value; // Not owned
|
||||
}
|
||||
|
||||
private delegate bool InvokeGodotClassStaticMethodDelegate(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret);
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe godot_bool CallStatic(IntPtr scriptPtr, godot_string_name* method,
|
||||
godot_variant** args, int argCount, godot_variant_call_error* refCallError, godot_variant* ret)
|
||||
{
|
||||
// TODO: Optimize with source generators and delegate pointers.
|
||||
|
||||
try
|
||||
{
|
||||
Type scriptType = _scriptTypeBiMap.GetScriptType(scriptPtr);
|
||||
|
||||
Type? top = scriptType;
|
||||
Type native = GodotObject.InternalGetClassNativeBase(top);
|
||||
|
||||
while (top != null && top != native)
|
||||
{
|
||||
var invokeGodotClassStaticMethod = top.GetMethod(
|
||||
"InvokeGodotClassStaticMethod",
|
||||
BindingFlags.DeclaredOnly | BindingFlags.Static |
|
||||
BindingFlags.NonPublic | BindingFlags.Public);
|
||||
|
||||
if (invokeGodotClassStaticMethod != null)
|
||||
{
|
||||
var invoked = invokeGodotClassStaticMethod.CreateDelegate<InvokeGodotClassStaticMethodDelegate>()(
|
||||
CustomUnsafe.AsRef(method), new NativeVariantPtrArgs(args, argCount), out godot_variant retValue);
|
||||
if (invoked)
|
||||
{
|
||||
*ret = retValue;
|
||||
return godot_bool.True;
|
||||
}
|
||||
}
|
||||
|
||||
top = top.BaseType;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionUtils.LogException(e);
|
||||
*ret = default;
|
||||
return godot_bool.False;
|
||||
}
|
||||
|
||||
*ret = default;
|
||||
(*refCallError).Error = godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD;
|
||||
return godot_bool.False;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe void GetPropertyDefaultValues(IntPtr scriptPtr,
|
||||
delegate* unmanaged<IntPtr, void*, int, void> addDefValFunc)
|
||||
|
||||
Reference in New Issue
Block a user