Facepunch.Steamworks/Generator/CodeWriter/Interface.cs

62 lines
1.8 KiB
C#
Raw Normal View History

2016-10-25 18:16:02 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Generator
{
public partial class CodeWriter
{
//
// Writes the RustNative.Platform.Interface
//
void PlatformInterface()
{
StartBlock( $"internal static partial class Platform" );
{
2016-11-02 23:22:11 +03:00
StartBlock( $"internal interface Interface : IDisposable" );
2016-10-25 18:16:02 +03:00
{
WriteLine( "// Implementation should return true if _ptr is non null" );
WriteLine( "bool IsValid { get; } " );
WriteLine();
foreach ( var m in def.methods.OrderBy( x => x.ClassName ) )
{
2016-10-25 18:37:48 +03:00
if ( ShouldIgnoreClass( m.ClassName ) ) continue;
2016-10-25 18:16:02 +03:00
PlatformInterfaceMethod( m );
}
}
EndBlock();
}
EndBlock();
}
private void PlatformInterfaceMethod( SteamApiDefinition.MethodDef m )
{
var arguments = BuildArguments( m.Params );
var ret = new Argument( "return", m.ReturnType, TypeDefs );
var methodName = m.Name;
if ( LastMethodName == methodName )
methodName = methodName + "0";
var flatName = $"SteamAPI_{m.ClassName}_{methodName}";
if ( m.ClassName == "SteamApi" )
flatName = methodName;
2016-10-26 13:08:32 +03:00
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( true, true ) ) );
2016-10-25 18:16:02 +03:00
if ( argstring != "" ) argstring = $" {argstring} ";
WriteLine( $"{ret.Return()} {m.ClassName}_{methodName}({argstring});" );
LastMethodName = m.Name;
}
}
}