mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-03 03:48:24 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
63 lines
1.5 KiB
C#
63 lines
1.5 KiB
C#
namespace Facepunch.InteropGen;
|
|
|
|
public class ArgManagedClass : Arg
|
|
{
|
|
public Class Class { get; set; }
|
|
|
|
|
|
public ArgManagedClass( Class c, string name, string[] flags )
|
|
{
|
|
Class = c;
|
|
Name = name;
|
|
Flags = flags;
|
|
}
|
|
|
|
public override string ManagedType => "global::" + Class.ManagedNameWithNamespace;
|
|
|
|
|
|
public override string ManagedDelegateType => "uint";
|
|
|
|
public override string GetManagedDelegateType( bool incoming )
|
|
{
|
|
return "uint";
|
|
}
|
|
|
|
public override string NativeType => $"uint";
|
|
|
|
public override string NativeDelegateType => "uint";
|
|
|
|
public override string FromInterop( bool native, string code = null )
|
|
{
|
|
code ??= Name;
|
|
|
|
//
|
|
// Passing a managed class to native. Incoming is a pointer - so we crea
|
|
// a new instance of the class. In reality we should only be calling this
|
|
// once per class to save a new instance.
|
|
//
|
|
if ( native )
|
|
{
|
|
return code;
|
|
}
|
|
|
|
//
|
|
// Getting a managed class back from interop. We use Facepunch.Interop.NativePointer's built in
|
|
// function to try to convert it from a GHandle to a Facepunch.Interop.NativePointer, then to the
|
|
// target class.
|
|
//
|
|
return $"Sandbox.InteropSystem.Get<{Class.ManagedNameWithNamespace}>( {code} )";
|
|
}
|
|
|
|
public override string ToInterop( bool native, string code = null )
|
|
{
|
|
code ??= Name;
|
|
|
|
//
|
|
// Passing a managed class to native - we just use the .NativePointer property
|
|
// Which should be using the NativePointer class to create a GCHandle.
|
|
//
|
|
return !native ? $" Sandbox.InteropSystem.GetAddress( {code}, true )" : $"{code}";
|
|
}
|
|
|
|
}
|