mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-09 06:48:34 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
namespace Facepunch.InteropGen;
|
|
|
|
[TypeName( "string" )]
|
|
public class ArgString : Arg
|
|
{
|
|
public override string ManagedType => "string";
|
|
public override string ManagedDelegateType => "IntPtr";
|
|
public override string NativeType => "const char*";
|
|
|
|
public override string ReturnWrapCall( string call, bool native )
|
|
{
|
|
return native ? $"return (const char*) SafeReturnString( (const char *) {call} );" : base.ReturnWrapCall( call, native );
|
|
}
|
|
|
|
public override string ToInterop( bool native, string code = null )
|
|
{
|
|
code ??= Name;
|
|
|
|
return !native
|
|
? IsReturn ? $"{Definition.Current.StringTools}.GetTemporaryStringPointerForNative( {code} )" : $"_str_{code}.Pointer"
|
|
: base.ToInterop( native, code );
|
|
}
|
|
|
|
public override string FromInterop( bool native, string code = null )
|
|
{
|
|
code ??= Name;
|
|
|
|
return !native ? $"{Definition.Current.StringTools}.GetString( {code} )" : base.ToInterop( native, code );
|
|
}
|
|
|
|
public override string WrapFunctionCall( string functionCall, bool native )
|
|
{
|
|
if ( !native && HasFlag( "out" ) )
|
|
{
|
|
return $"IntPtr _outptr_{Name} = default;\n\n" +
|
|
$"try\n" +
|
|
$"{{\n" +
|
|
$" {functionCall}\n" +
|
|
$"}}\n" +
|
|
$"finally\n" +
|
|
$"{{\n" +
|
|
$" {Name} = {Definition.Current.StringTools}.GetString( _outptr_{Name} );\n" +
|
|
$"}}\n";
|
|
}
|
|
else if ( !native )
|
|
{
|
|
return $"var _str_{Name} = new {Definition.Current.StringTools}.InteropString( {Name} ); try {{ {functionCall} }} finally {{ _str_{Name}.Free(); }} ";
|
|
}
|
|
|
|
return base.WrapFunctionCall( functionCall, native );
|
|
}
|
|
}
|