Added example plugin project

This commit is contained in:
Alessandro Proto 2023-01-16 18:53:32 +01:00
parent a652992861
commit 79c232a4ac
3 changed files with 71 additions and 0 deletions

View file

@ -5,6 +5,8 @@ VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capy64", "Capy64\Capy64.csproj", "{D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capy64", "Capy64\Capy64.csproj", "{D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExamplePlugin", "ExamplePlugin\ExamplePlugin.csproj", "{7176CC2D-BB9E-4512-B216-CC49E9F8A89D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Debug|Any CPU.Build.0 = Debug|Any CPU {D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Release|Any CPU.ActiveCfg = Release|Any CPU {D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Release|Any CPU.Build.0 = Release|Any CPU {D38FAB55-99A5-4C5B-9BF7-CC76443AC43A}.Release|Any CPU.Build.0 = Release|Any CPU
{7176CC2D-BB9E-4512-B216-CC49E9F8A89D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7176CC2D-BB9E-4512-B216-CC49E9F8A89D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7176CC2D-BB9E-4512-B216-CC49E9F8A89D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7176CC2D-BB9E-4512-B216-CC49E9F8A89D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Capy64\Capy64.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project>

48
ExamplePlugin/MyPlugin.cs Normal file
View file

@ -0,0 +1,48 @@
using Capy64;
using Capy64.API;
using KeraLua;
namespace ExamplePlugin;
public class MyPlugin : IPlugin
{
private static IGame _game;
public MyPlugin(IGame game)
{
_game = game;
}
private static LuaRegister[] MyLib = new LuaRegister[]
{
new()
{
name = "hello",
function = L_HelloWorld,
},
new(),
};
public void LuaInit(Lua L)
{
L.RequireF("mylib", OpenLib, false);
}
private static int OpenLib(IntPtr state)
{
var L = Lua.FromIntPtr(state);
L.NewLib(MyLib);
return 1;
}
private static int L_HelloWorld(IntPtr state)
{
var L = Lua.FromIntPtr(state);
L.PushString("Hello, World");
return 1;
}
}