Merged projects with plugins and modules
This commit is contained in:
22
Plugins/DiscordBotUI/Delegates.cs
Normal file
22
Plugins/DiscordBotUI/Delegates.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using CppWrapper.Objects;
|
||||
|
||||
namespace DiscordBotUI
|
||||
{
|
||||
public abstract class Delegates
|
||||
{
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ProcessApplicationData(ref ApplicationStruct appData);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ProcessComplexObject(ref ComplexObject complexObject);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void CsharpFunctionDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void SetCsharpFunctionPointerDelegate(IntPtr funcPtr);
|
||||
}
|
||||
}
|
||||
13
Plugins/DiscordBotUI/DiscordBotUI.csproj
Normal file
13
Plugins/DiscordBotUI/DiscordBotUI.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\DiscordBotCore\DiscordBotCore.csproj" />
|
||||
<ProjectReference Include="..\CppWrapper\CppWrapper.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
52
Plugins/DiscordBotUI/Entry.cs
Normal file
52
Plugins/DiscordBotUI/Entry.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using DiscordBotCore.Interfaces;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Others.Actions;
|
||||
|
||||
using CppWrapper.Objects;
|
||||
using CppWrapper.LibraryManagement;
|
||||
using DiscordBotCore;
|
||||
using CppWrapper;
|
||||
|
||||
namespace DiscordBotUI;
|
||||
|
||||
public class Entry : ICommandAction
|
||||
{
|
||||
public string ActionName => "cppui";
|
||||
|
||||
public string? Description => "A C++ linker to the C++ UI for the bot";
|
||||
|
||||
public string? Usage => "cppui";
|
||||
|
||||
public IEnumerable<InternalActionOption> ListOfOptions => [];
|
||||
|
||||
public InternalActionRunType RunType => InternalActionRunType.OnStartupAndCall;
|
||||
|
||||
public async Task Execute(string[]? args)
|
||||
{
|
||||
try{
|
||||
|
||||
string appUiComponent = "./Data/Test/libtestlib.dll";
|
||||
|
||||
ExternLibrary externalLibrary = new ExternLibrary(appUiComponent);
|
||||
externalLibrary.InitializeLibrary();
|
||||
|
||||
externalLibrary.SetExternFunctionSetterPointerToCustomDelegate<Delegates.SetCsharpFunctionPointerDelegate, Delegates.CsharpFunctionDelegate>("setCSharpFunctionPointer", () =>
|
||||
{
|
||||
Console.WriteLine("Hello from C#. This code is called from the C# function");
|
||||
});
|
||||
|
||||
Delegates.ProcessComplexObject processObj = externalLibrary.GetDelegateForFunctionPointer<Delegates.ProcessComplexObject>("ProcessComplexObject");
|
||||
|
||||
ComplexObject complexObject = new ComplexObject(10, 10.5, "Hello from C#");
|
||||
processObj(ref complexObject);
|
||||
|
||||
Console.WriteLine($"Integer: {complexObject.Integer}");
|
||||
Console.WriteLine($"Double: {complexObject.DoubleValue}");
|
||||
Console.WriteLine($"String: {complexObject.strValue}");
|
||||
|
||||
externalLibrary.FreeLibrary();
|
||||
} catch (Exception dllException) {
|
||||
Application.CurrentApplication.Logger.LogException(dllException, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user