This commit is contained in:
Garry Newman 2016-10-29 13:13:25 +01:00
parent a333bc3860
commit 14ee1314de
8 changed files with 7024 additions and 10316 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -73,10 +73,6 @@ private void PlatformClass( string className, SteamApiDefinition.MethodDef[] met
WriteLine();
}
private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef methodDef )
{
var arguments = BuildArguments( methodDef.Params );
@ -97,6 +93,7 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
if ( argstring != "" ) argstring = $" {argstring} ";
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
{
// var vars = string.Join( " + \",\" + ", arguments.Where( x => !x.InteropParameter( true, true ).StartsWith( "out " ) ).Select( x => x.Name ) );
// if ( vars != "" ) vars = "\" + " + vars + " + \"";
@ -124,8 +121,6 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
if ( retcode != "" )
retcode = "var ret = ";
}
}
@ -134,7 +129,7 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
if ( methodDef.NeedsSelfPointer )
argstring = "_ptr" + ( argstring.Length > 0 ? ", " : "" ) + argstring;
WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" );
WriteLine( $"{retcode}Native.{flatName}({argstring});" );
WriteLines( AfterLines );
@ -143,13 +138,31 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
WriteLine( "return ret;" );
}
}
EndBlock();
LastMethodName = methodDef.Name;
}
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( ShouldIgnoreClass( className ) ) return;
WriteLine( $"//" );
WriteLine( $"// {className} " );
WriteLine( $"//" );
LastMethodName = "";
foreach ( var m in methodDef )
{
InteropClassMethod( libraryName, className, m );
}
WriteLine();
}
private void InteropClassMethod( string library, string classname, SteamApiDefinition.MethodDef methodDef )
{
var arguments = BuildArguments( methodDef.Params );
@ -165,7 +178,6 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
if ( classname == "SteamApi" )
flatName = methodName;
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack, true ) ) );
if ( methodDef.NeedsSelfPointer )
@ -175,31 +187,14 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
if ( argstring != "" ) argstring = $" {argstring} ";
WriteLine( $"[DllImportAttribute( \"{library}\", EntryPoint = \"{flatName}\" )]" );
Write( $"[DllImportAttribute( \"{library}\" )] " );
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
WriteLine( $"internal static extern {ret.Return()} {methodName}({argstring});" );
WriteLine( $"internal static extern {ret.Return()} {flatName}({argstring});" );
LastMethodName = methodDef.Name;
}
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( ShouldIgnoreClass( className ) ) return;
StartBlock( $"internal static unsafe class {className}" );
LastMethodName = "";
foreach ( var m in methodDef )
{
InteropClassMethod( libraryName, className, m );
}
EndBlock();
WriteLine();
}
}
}

View File

@ -13,24 +13,32 @@ public partial class CodeWriter
private StringBuilder sb = new StringBuilder();
private int indent = 0;
public string Indent { get { return new string( '\t', indent ); } }
private bool skipIndent = false;
public string Indent { get { if ( skipIndent ) { return ""; } return new string( '\t', indent ); } }
private void EndBlock( string end = "" )
{
indent--;
sb.AppendLine( $"{Indent}}}{end}" );
WriteLine( "}" + end );
}
private void WriteLine( string v = "" )
{
sb.AppendLine( $"{Indent}{v}" );
skipIndent = false;
}
private void Write( string v = "" )
{
sb.Append( $"{Indent}{v}" );
skipIndent = true;
}
private void StartBlock( string v )
{
sb.AppendLine( $"{Indent}{v}" );
sb.AppendLine( $"{Indent}{{" );
WriteLine( v );
WriteLine( "{" );
indent++;
}

View File

@ -62,7 +62,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Compile Include="CodeWriter.PlatformClass.cs" />
<Compile Include="CodeWriter\PlatformClass.cs" />
<None Include="packages.config" />
<None Include="steam_api.json" />
</ItemGroup>