Skip to content

Commit 3f7afa5

Browse files
committed
Fixed many things and added NativeCallback utility.
1 parent 0177f66 commit 3f7afa5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1251
-453
lines changed

Hexa.NET.Bgfx/Bgfx.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Hexa.NET.Bgfx
44
{
5+
using HexaGen.Runtime;
56
using System.Numerics;
67
using System.Runtime.InteropServices;
78

@@ -10,6 +11,24 @@ public static unsafe partial class Bgfx
1011
static Bgfx()
1112
{
1213
InitApi();
14+
15+
LibraryLoader.CustomLoadFolders.Add("your/custom/path/relative/to/app");
16+
17+
LibraryLoader.CustomLoadFolders.Add("C:/your/custom/path/absolute");
18+
19+
LibraryLoader.InterceptLibraryName = (ref string libraryName) =>
20+
{
21+
// note extensions will be automatically added if not present.
22+
if (libraryName == "cimgui")
23+
{
24+
libraryName = "customCimguiName";
25+
}
26+
};
27+
28+
LibraryLoader.ResolvePath = (string libraryName, out string pathToLibrary) =>
29+
{
30+
pathToLibrary = Path.GetFullPath(libraryName);
31+
};
1332
}
1433

1534
public static nint GetLibraryName()

Hexa.NET.Bgfx/LibraryLoader.cs

Lines changed: 0 additions & 128 deletions
This file was deleted.

Hexa.NET.Daxa/source.lnk

1.13 KB
Binary file not shown.

HexaGen.Core/CSharp/CsFunctionVariation.cs

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace HexaGen.Core.CSharp
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Text;
6-
77

88
public class CsFunctionVariation : ICsFunction, ICloneable<CsFunctionVariation>, IHasIdentifier
99
{
@@ -115,6 +115,12 @@ public string BuildFunctionHeaderId(WriteFunctionFlags flags)
115115
return Identifier = $"{Name}({signature})";
116116
}
117117

118+
public string BuildFunctionHeaderId(string alias, WriteFunctionFlags flags)
119+
{
120+
string signature = BuildFunctionSignature(this, false, false, flags);
121+
return Identifier = $"{alias}({signature})";
122+
}
123+
118124
public string BuildFunctionHeader(CsType csReturnType, WriteFunctionFlags flags, bool generateMetadata)
119125
{
120126
string signature = BuildFunctionSignature(this, generateMetadata, true, flags);
@@ -128,6 +134,79 @@ public string BuildFunctionHeader(CsType csReturnType, WriteFunctionFlags flags,
128134
}
129135
}
130136

137+
public string BuildFunctionHeader(string alias, CsType csReturnType, WriteFunctionFlags flags, bool generateMetadata)
138+
{
139+
string signature = BuildFunctionSignature(this, generateMetadata, true, flags);
140+
if (IsGeneric)
141+
{
142+
return Identifier = $"{csReturnType.Name} {alias}<{BuildGenericSignature()}>({signature}) {BuildGenericConstraint()}";
143+
}
144+
else
145+
{
146+
return Identifier = $"{csReturnType.Name} {alias}({signature})";
147+
}
148+
}
149+
150+
public string BuildFunctionOverload(WriteFunctionFlags flags)
151+
{
152+
string signature = BuildFunctionOverload(this, flags);
153+
if (IsGeneric)
154+
{
155+
return $"{Name}<{BuildGenericSignature()}>({signature})";
156+
}
157+
else
158+
{
159+
return $"{Name}({signature})";
160+
}
161+
}
162+
163+
protected virtual string BuildFunctionOverload(CsFunctionVariation variation, WriteFunctionFlags flags)
164+
{
165+
int offset = flags == WriteFunctionFlags.None ? 0 : 1;
166+
StringBuilder sb = new();
167+
bool isFirst = true;
168+
169+
if (flags == WriteFunctionFlags.Extension)
170+
{
171+
isFirst = false;
172+
var first = variation.Parameters[0];
173+
sb.Append("this");
174+
175+
sb.Append($" {first.Name}");
176+
}
177+
178+
for (int i = offset; i < variation.Parameters.Count; i++)
179+
{
180+
bool written = false;
181+
var param = variation.Parameters[i];
182+
183+
if (param.DefaultValue != null)
184+
continue;
185+
186+
if (!isFirst)
187+
sb.Append(", ");
188+
189+
if (param.Type.IsRef)
190+
{
191+
sb.Append("ref");
192+
written = true;
193+
}
194+
195+
if (param.Type.IsOut)
196+
{
197+
sb.Append("out");
198+
written = true;
199+
}
200+
201+
if (written) sb.Append(' ');
202+
sb.Append(param.Name);
203+
204+
isFirst = false;
205+
}
206+
207+
return sb.ToString();
208+
}
209+
131210
public string BuildConstructorSignatureIdentifier()
132211
{
133212
return Identifier = $"{StructName}({BuildConstructorSignature(false, false, false)})";

HexaGen.Core/CSharp/FunctionAlias.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace HexaGen.Core.CSharp
2+
{
3+
public class FunctionAlias
4+
{
5+
public FunctionAlias(string exportedName, string exportedAliasName, string friendlyName, string? comment)
6+
{
7+
ExportedName = exportedName;
8+
ExportedAliasName = exportedAliasName;
9+
FriendlyName = friendlyName;
10+
Comment = comment;
11+
}
12+
13+
public string ExportedName { get; set; }
14+
15+
public string ExportedAliasName { get; set; }
16+
17+
public string FriendlyName { get; set; }
18+
19+
public string? Comment { get; set; }
20+
}
21+
}

HexaGen.Core/DummyCodeWriter.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace HexaGen
2+
{
3+
using HexaGen.Core;
4+
5+
public sealed class DummyCodeWriter : ICodeWriter, IDisposable
6+
{
7+
private int indentLevel;
8+
9+
public int IndentLevel { get => indentLevel; }
10+
11+
public void BeginBlock(string content)
12+
{
13+
}
14+
15+
public void Dispose()
16+
{
17+
}
18+
19+
public void EndBlock()
20+
{
21+
}
22+
23+
public void Indent(int count = 1)
24+
{
25+
indentLevel += count;
26+
}
27+
28+
public IDisposable PushBlock(string marker = "{")
29+
{
30+
return new DummyBlock(this);
31+
}
32+
33+
private struct DummyBlock : IDisposable
34+
{
35+
private DummyCodeWriter dummyCodeWriter;
36+
37+
public DummyBlock(DummyCodeWriter dummyCodeWriter)
38+
{
39+
this.dummyCodeWriter = dummyCodeWriter;
40+
}
41+
42+
public void Dispose()
43+
{
44+
dummyCodeWriter.EndBlock();
45+
}
46+
}
47+
48+
public void Unindent(int count = 1)
49+
{
50+
indentLevel -= count;
51+
}
52+
53+
public void Write(char chr)
54+
{
55+
}
56+
57+
public void Write(string @string)
58+
{
59+
}
60+
61+
public void WriteLine()
62+
{
63+
}
64+
65+
public void WriteLine(string @string)
66+
{
67+
}
68+
69+
public void WriteLines(string? @string)
70+
{
71+
}
72+
73+
public void WriteLines(IEnumerable<string> lines)
74+
{
75+
}
76+
}
77+
}

HexaGen.Core/HexaGen.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88

99
<AssemblyVersion>1.1.1</AssemblyVersion>
10-
<PackageVersion>1.1.7-rc2</PackageVersion>
10+
<PackageVersion>1.1.7-rc5</PackageVersion>
1111
<Description></Description>
1212
<PackageTags></PackageTags>
1313
<Authors>Juna Meinhold</Authors>

0 commit comments

Comments
 (0)