-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from dcronqvist/dev
Update to automatic generation of native binding
- Loading branch information
Showing
73 changed files
with
4,294 additions
and
4,380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Top-most EditorConfig file | ||
root = true | ||
|
||
# C# files | ||
[*.cs] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Will create a json representation of the debug launch arguments for a specified dll file | ||
# Usage: ./gen_debug_args.sh <path_to_dll> <cwd> <args> | ||
|
||
# Check if the correct number of arguments were passed | ||
if [ "$#" -ne 3 ]; then | ||
echo "Usage: ./gen_debug_args.sh <path_to_dll> <cwd> <args>" | ||
exit 1 | ||
fi | ||
|
||
# Get absolute path to the dll | ||
dll_path=$(realpath $1) | ||
|
||
# Get absolute path to the cwd | ||
cwd=$(realpath $2) | ||
|
||
# Create the json representation of the debug launch arguments | ||
launch_args="{\"type\":\"coreclr\",\"request\":\"launch\",\"program\":\"$dll_path\",\"cwd\":\"$cwd\",\"just_my_code\":false,\"args\":\"$3\"}" | ||
|
||
# Url encode the json representation | ||
launch_args=$(echo $launch_args | jq -r @uri) | ||
|
||
# Print the url encoded json representation | ||
echo $launch_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="HtmlAgilityPack" Version="1.11.61" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace DotGLFW.Generator; | ||
|
||
public static partial class Extensions | ||
{ | ||
public static string Remove(this string str, string toRemove) | ||
{ | ||
return str.Replace(toRemove, ""); | ||
} | ||
|
||
public static string FixSpaces(this string str) | ||
{ | ||
if (!str.Contains(" ")) | ||
{ | ||
return str; | ||
} | ||
|
||
if (!str.Split(" ").Where(x => x != "").Any()) | ||
{ | ||
return str; | ||
} | ||
|
||
return str.Split(" ").Where(x => x != "").Aggregate((x, y) => $"{x} {y}"); | ||
} | ||
|
||
public static string FixNewlines(this string str) | ||
{ | ||
if (!str.Contains("\n")) | ||
{ | ||
return str; | ||
} | ||
|
||
if (!str.Split("\n").Where(x => x != "").Any()) | ||
{ | ||
return str; | ||
} | ||
|
||
return str.Split("\n").Where(x => x != "").Aggregate((x, y) => $"{x} {y}"); | ||
} | ||
|
||
public static int Count(this string str, char c) | ||
{ | ||
return str.Count(x => x == c); | ||
} | ||
|
||
public static string Repeat(this string str, int count) | ||
{ | ||
return string.Concat(Enumerable.Repeat(str, count)); | ||
} | ||
|
||
public static string Capitalize(this string str) | ||
{ | ||
if (str.Length <= 1) | ||
return str.ToUpper(); | ||
|
||
return char.ToUpper(str[0]) + str.Substring(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.IO; | ||
|
||
namespace DotGLFW.Generator; | ||
|
||
public class GLFWProvider : IGLFWProvider | ||
{ | ||
private readonly string _glfwRepoPath; | ||
|
||
public GLFWProvider(string glfwRepoPath) | ||
{ | ||
_glfwRepoPath = glfwRepoPath; | ||
} | ||
|
||
public string ReadGLFWRepoFile(string filePath) | ||
{ | ||
using var reader = new StreamReader(Path.Combine(_glfwRepoPath, filePath)); | ||
return reader.ReadToEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace DotGLFW.Generator; | ||
|
||
public partial class Generator | ||
{ | ||
public void GenerateEnums(ParsedAPI api) | ||
{ | ||
var enums = api.MacroCollections; | ||
enums.ToList().ForEach(GenerateEnum); | ||
} | ||
|
||
private void GenerateEnum(MacroCollection macroCollection) | ||
{ | ||
var content = new StringBuilder(); | ||
WriteFileHeader(content); | ||
|
||
content.AppendLine("using static DotGLFW.NativeGlfw;"); | ||
content.AppendLine("namespace DotGLFW;"); | ||
content.AppendLine(); | ||
content.AppendLine("/// <summary>"); | ||
content.AppendLine($"/// Wrapping enum for {macroCollection.Name}."); | ||
content.AppendLine("/// </summary>"); | ||
content.AppendLine($"public enum {macroCollection.Name}"); | ||
content.AppendLine("{"); | ||
|
||
foreach (var macro in macroCollection.Macros) | ||
{ | ||
var csharpName = ConvertEnumName(macro.Name, macroCollection.PrefixToRemove, macroCollection.SuffixToRemove); | ||
if (macro.TryGetValue(out var value)) | ||
{ | ||
content.AppendLine($" /// <inheritdoc cref=\"NativeGlfw.{macro.Name}\" />"); | ||
content.AppendLine($" {csharpName} = NativeGlfw.{macro.Name},"); | ||
} | ||
} | ||
|
||
content.AppendLine("}"); | ||
|
||
_sourceWriter.WriteToFile($"Enum.{macroCollection.Name}.gen.cs", content.ToString()); | ||
} | ||
|
||
private string ConvertEnumName(string name, string prefixToRemove, string suffixToRemove) | ||
{ | ||
string withoutPrefixSuffix = name; | ||
if (!string.IsNullOrEmpty(prefixToRemove)) | ||
{ | ||
withoutPrefixSuffix = withoutPrefixSuffix.Replace(prefixToRemove, ""); | ||
} | ||
if (!string.IsNullOrEmpty(suffixToRemove)) | ||
{ | ||
withoutPrefixSuffix = withoutPrefixSuffix.Replace(suffixToRemove, ""); | ||
} | ||
|
||
var split = withoutPrefixSuffix.Split('_'); | ||
var result = new StringBuilder(); | ||
foreach (var part in split) | ||
{ | ||
result.Append(part.ToLower().Capitalize()); | ||
} | ||
var final = result.ToString(); | ||
if (char.IsDigit(final[0])) | ||
{ | ||
final = "D" + final; | ||
} | ||
return final; | ||
} | ||
} |
Oops, something went wrong.