diff --git a/GlitchyEditor/src/Extensions/Engine/ScriptGlueExtension.bf b/GlitchyEditor/src/Extensions/Engine/ScriptGlueExtension.bf index 1e37546..bf008bb 100644 --- a/GlitchyEditor/src/Extensions/Engine/ScriptGlueExtension.bf +++ b/GlitchyEditor/src/Extensions/Engine/ScriptGlueExtension.bf @@ -10,15 +10,21 @@ extension ScriptGlue { OnRegisterNativeCalls.Add(new => RegisterExtensionCalls); } - + + [RegisterMethod(IsExtension = true)] private static void RegisterExtensionCalls() { - EngineFunctions.[Friend]_functions.ImGuiExtension_ShowAssetDropTarget = => ImGuiExtension_ShowAssetDropTarget; } [RegisterCall(EngineResultAsBool = true, IsExtension = true)] - public static EngineResult ImGuiExtension_ShowAssetDropTarget(ref AssetHandle assetHandle) + static EngineResult ImGuiExtension_ShowAssetDropTarget(ref AssetHandle assetHandle) { return ComponentEditWindow.ShowAssetDropTarget(ref assetHandle) ? .Ok : .False; } + + [RegisterCall(IsExtension = true), CallingConvention(.Cdecl)] + static void ImGuiExtension_ListElementGrabber() + { + ImGui.ImGui.ListElementGrabber(); + } } diff --git a/GlitchyEngine/src/Scripting/ScriptGlue.bf b/GlitchyEngine/src/Scripting/ScriptGlue.bf index c01d096..8b5257f 100644 --- a/GlitchyEngine/src/Scripting/ScriptGlue.bf +++ b/GlitchyEngine/src/Scripting/ScriptGlue.bf @@ -203,9 +203,11 @@ struct EngineFunctions } /* Adding this attribute to a method will log method entry and returned Result errors */ -[AttributeUsage(.Method)] +[AttributeUsage(.Method | .Constructor)] public struct RegisterMethodAttribute : Attribute, IOnMethodInit { + public bool IsExtension = false; + [Comptime] public void OnMethodInit(MethodInfo method, Self* prev) { @@ -213,12 +215,26 @@ public struct RegisterMethodAttribute : Attribute, IOnMethodInit int i = 0; - for (var methodInfo in typeof(ScriptGlue).GetMethods(.Static | .NonPublic | .FlattenHierarchy)) + BindingFlags flags = .Static; + + if (IsExtension) { - if (methodInfo.GetCustomAttribute() case .Ok(let attribute) && !attribute.IsExtension) + flags |= .DeclaredOnly; + } + + for (var methodInfo in typeof(ScriptGlue).GetMethods(flags)) + { + if (methodInfo.GetCustomAttribute() not case .Ok(let attribute)) + continue; + + if (IsExtension && attribute.IsExtension) + { + functionContent.AppendF($"EngineFunctions.[Friend]_functions.{methodInfo.Name} = => ScriptGlue.{methodInfo.Name};\n"); + i++; + } + else if (!IsExtension && !attribute.IsExtension) { functionContent.AppendF($"_functions.{methodInfo.Name} = => ScriptGlue.[Friend]{methodInfo.Name};\n"); - //functionContent.AppendF($"functions[{i}] = (void*)( => {methodInfo.Name});\n"); i++; } } @@ -1467,7 +1483,7 @@ static class ScriptGlue } [RegisterCall, CallingConvention(.Cdecl)] - public static void Serialization_DeserializeField(void* internalContext, SerializationType expectedType, StringView fieldName, uint8* target, out SerializationType actualType) + static void Serialization_DeserializeField(void* internalContext, SerializationType expectedType, StringView fieldName, uint8* target, out SerializationType actualType) { SerializedObject context = Internal.UnsafeCastToObject(internalContext) as SerializedObject; @@ -1477,7 +1493,7 @@ static class ScriptGlue } [RegisterCall, CallingConvention(.Cdecl)] - public static void Serialization_GetObject(void* internalContext, UUID id, out void* objectContext) + static void Serialization_GetObject(void* internalContext, UUID id, out void* objectContext) { SerializedObject context = Internal.UnsafeCastToObject(internalContext) as SerializedObject; @@ -1494,7 +1510,7 @@ static class ScriptGlue } [RegisterCall, CallingConvention(.Cdecl)] - public static void Serialization_GetObjectTypeName(void* internalContext, out StringView fullTypeName) + static void Serialization_GetObjectTypeName(void* internalContext, out StringView fullTypeName) { SerializedObject context = Internal.UnsafeCastToObject(internalContext) as SerializedObject; @@ -1657,15 +1673,5 @@ static class ScriptGlue return .Ok; } -#endregion - -#region ImGui Extension - - [RegisterCall, CallingConvention(.Cdecl)] - static void ImGuiExtension_ListElementGrabber() - { - ImGui.ImGui.ListElementGrabber(); - } - #endregion } \ No newline at end of file