213 lines
8.9 KiB
C#
213 lines
8.9 KiB
C#
// Generated by `wit-bindgen` 0.57.1. DO NOT EDIT!
|
|
// <auto-generated />
|
|
#nullable enable
|
|
|
|
namespace PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0;
|
|
|
|
public interface IContextImports {
|
|
|
|
/**
|
|
* A contextual handle for plugin-related operations.
|
|
*/
|
|
|
|
public class Context: global::System.IDisposable {
|
|
internal int Handle { get; set; }
|
|
|
|
public readonly record struct THandle(int Handle);
|
|
|
|
public Context(THandle handle) {
|
|
Handle = handle.Handle;
|
|
}
|
|
|
|
public void Dispose() {
|
|
Dispose(true);
|
|
}
|
|
|
|
[global::System.Runtime.InteropServices.DllImportAttribute("pumpkin:plugin/context@0.1.0", EntryPoint = "[resource-drop]context"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
|
|
private static extern void wasmImportResourceDrop(int p0);
|
|
|
|
protected virtual void Dispose(bool disposing) {
|
|
if (disposing && Handle != 0) {
|
|
wasmImportResourceDrop(Handle);
|
|
Handle = 0;
|
|
}
|
|
}
|
|
|
|
public unsafe void RegisterEvent(uint handlerId, global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IEventImports.EventType eventType, global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IEventImports.EventPriority eventPriority, bool blocking)
|
|
{
|
|
var handle = this.Handle;
|
|
ContextImportsInterop.Context.RegisterEventWasmInterop.wasmImportRegisterEvent(handle, unchecked((int)(handlerId)), (int)eventType, (int)eventPriority, (blocking ? 1 : 0));
|
|
|
|
}
|
|
|
|
public unsafe void RegisterCommand(global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.ICommandImports.Command command, string permission)
|
|
{
|
|
var cleanups = new global::System.Collections.Generic.List<global::System.Action>();
|
|
var handle = this.Handle;
|
|
var handle0 = command.Handle;
|
|
command.Handle = 0;
|
|
|
|
var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(permission);
|
|
var length = utf8Bytes.Length;
|
|
var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned);
|
|
var strPtr = gcHandle.AddrOfPinnedObject();
|
|
|
|
cleanups.Add(()=> gcHandle.Free());
|
|
ContextImportsInterop.Context.RegisterCommandWasmInterop.wasmImportRegisterCommand(handle, handle0, strPtr.ToInt32(), length);
|
|
|
|
foreach (var cleanup in cleanups)
|
|
{
|
|
cleanup();
|
|
}
|
|
|
|
}
|
|
|
|
public unsafe void RegisterPermission(global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IPermissionImports.Permission permission)
|
|
{
|
|
var cleanups = new global::System.Collections.Generic.List<global::System.Action>();
|
|
var handle = this.Handle;
|
|
|
|
var utf8Bytes = global::System.Text.Encoding.UTF8.GetBytes(permission.node);
|
|
var length = utf8Bytes.Length;
|
|
var gcHandle = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes, global::System.Runtime.InteropServices.GCHandleType.Pinned);
|
|
var strPtr = gcHandle.AddrOfPinnedObject();
|
|
|
|
cleanups.Add(()=> gcHandle.Free());
|
|
|
|
var utf8Bytes1 = global::System.Text.Encoding.UTF8.GetBytes(permission.description);
|
|
var length2 = utf8Bytes1.Length;
|
|
var gcHandle3 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes1, global::System.Runtime.InteropServices.GCHandleType.Pinned);
|
|
var strPtr0 = gcHandle3.AddrOfPinnedObject();
|
|
|
|
cleanups.Add(()=> gcHandle3.Free());
|
|
|
|
int lowered;
|
|
int lowered10;
|
|
|
|
switch (permission.@default.Tag) {
|
|
case 0: {
|
|
|
|
lowered = 0;
|
|
lowered10 = 0;
|
|
|
|
break;
|
|
}
|
|
case 1: {
|
|
|
|
lowered = 1;
|
|
lowered10 = 0;
|
|
|
|
break;
|
|
}
|
|
case 2: {
|
|
global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IPermissionImports.PermissionLevel payload9 = permission.@default.AsOp;
|
|
|
|
lowered = 2;
|
|
lowered10 = (int)payload9;
|
|
|
|
break;
|
|
}
|
|
|
|
default: throw new global::System.ArgumentException("invalid discriminant: " + permission.@default);
|
|
}
|
|
|
|
void* address;
|
|
if ((12 * permission.children.Count) < 1024) {
|
|
var retArea = stackalloc uint[3 * permission.children.Count + 1];
|
|
address = MemoryHelper.AlignStackPtr(retArea, 4);
|
|
}
|
|
else
|
|
{
|
|
var bufferSize = 12 * (nuint)permission.children.Count;
|
|
address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(bufferSize, 4);
|
|
cleanups.Add(() => global::System.Runtime.InteropServices.NativeMemory.AlignedFree(address));
|
|
}
|
|
|
|
for (int index = 0; index < permission.children.Count; ++index) {
|
|
global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IPermissionImports.PermissionChild element11 = permission.children[index];
|
|
int basePtr12 = (int)address + (index * 12);
|
|
|
|
var utf8Bytes14 = global::System.Text.Encoding.UTF8.GetBytes(element11.node);
|
|
var length15 = utf8Bytes14.Length;
|
|
var gcHandle16 = global::System.Runtime.InteropServices.GCHandle.Alloc(utf8Bytes14, global::System.Runtime.InteropServices.GCHandleType.Pinned);
|
|
var strPtr13 = gcHandle16.AddrOfPinnedObject();
|
|
|
|
cleanups.Add(()=> gcHandle16.Free());
|
|
new global::System.Span<int>((void*)((byte*)basePtr12 + 4), 1)[0] = length15;
|
|
new global::System.Span<nint>((void*)((byte*)basePtr12 + 0), 1)[0] = (nint)strPtr13.ToInt32();
|
|
*(byte*)(basePtr12 + 8) = (byte)(element11.value ? 1 : 0);
|
|
|
|
}
|
|
|
|
var retArea17 = stackalloc uint[4];
|
|
var ptr = (nint)MemoryHelper.AlignStackPtr(retArea17, 4);
|
|
ContextImportsInterop.Context.RegisterPermissionWasmInterop.wasmImportRegisterPermission(handle, strPtr.ToInt32(), length, strPtr0.ToInt32(), length2, lowered, lowered10, (int)address, permission.children.Count, ptr);
|
|
|
|
Result<None, string> lifted;
|
|
|
|
switch (new global::System.Span<byte>((byte*)ptr + 0, 1)[0]) {
|
|
case 0: {
|
|
|
|
lifted = Result<None, string>.Ok(new global::PluginWorld.None());
|
|
break;
|
|
}
|
|
case 1: {
|
|
|
|
var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span<nint>((void*)((byte*)ptr + 4), 1)[0], new global::System.Span<int>((void*)((byte*)ptr + 8), 1)[0]);
|
|
if (new global::System.Span<int>((void*)((byte*)ptr + 8), 1)[0] > 0) {
|
|
global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span<nint>((void*)((byte*)ptr + 4), 1)[0]);
|
|
}
|
|
|
|
lifted = Result<None, string>.Err(str);
|
|
break;
|
|
}
|
|
|
|
default: throw new global::System.ArgumentException("invalid discriminant:" + new global::System.Span<byte>((byte*)ptr + 0, 1)[0]);
|
|
}
|
|
|
|
foreach (var cleanup in cleanups)
|
|
{
|
|
cleanup();
|
|
}
|
|
if (lifted.IsOk)
|
|
{
|
|
var tmp = lifted.AsOk;
|
|
return ;
|
|
}
|
|
else
|
|
{
|
|
throw new WitException<string>(lifted.AsErr!, 0);
|
|
}
|
|
|
|
}
|
|
|
|
public unsafe string GetDataFolder()
|
|
{
|
|
var handle = this.Handle;
|
|
|
|
var retArea = stackalloc uint[3];
|
|
var ptr = (nint)MemoryHelper.AlignStackPtr(retArea, 4);
|
|
ContextImportsInterop.Context.GetDataFolderWasmInterop.wasmImportGetDataFolder(handle, ptr);
|
|
|
|
var str = global::System.Text.Encoding.UTF8.GetString((byte*)new global::System.Span<nint>((void*)((byte*)ptr + 0), 1)[0], new global::System.Span<int>((void*)((byte*)ptr + 4), 1)[0]);
|
|
if (new global::System.Span<int>((void*)((byte*)ptr + 4), 1)[0] > 0) {
|
|
global::System.Runtime.InteropServices.NativeMemory.Free((void*)new global::System.Span<nint>((void*)((byte*)ptr + 0), 1)[0]);
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
public unsafe global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IServerImports.Server GetServer()
|
|
{
|
|
var handle = this.Handle;
|
|
var result = ContextImportsInterop.Context.GetServerWasmInterop.wasmImportGetServer(handle);
|
|
var resource = new global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IServerImports.Server(new global::PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0.IServerImports.Server.THandle(result));
|
|
return resource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|