Tools and libraries to glue C/C++ APIs to high-level languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

98 lines
3.8 KiB

using CppSharp.AST;
using CppSharp.Passes;
using System;
using System.IO;
namespace CppSharp
{
class SDL : ILibrary
{
public void Setup(Driver driver)
{
var options = driver.Options;
var module = options.AddModule("SDL");
module.Headers.Add("SDL.h");
options.OutputDir = "SDL";
var parserOptions = driver.ParserOptions;
var sdlPath = Path.Combine(GetExamplesDirectory("SDL"), "SDL-2.0/include");
parserOptions.AddIncludeDirs(sdlPath);
}
public void SetupPasses(Driver driver)
{
driver.Context.TranslationUnitPasses.RemovePrefix("SDL_");
driver.Context.TranslationUnitPasses.RemovePrefix("SCANCODE_");
driver.Context.TranslationUnitPasses.RemovePrefix("SDLK_");
driver.Context.TranslationUnitPasses.RemovePrefix("KMOD_");
driver.Context.TranslationUnitPasses.RemovePrefix("LOG_CATEGORY_");
}
public void Preprocess(Driver driver, ASTContext ctx)
{
ctx.IgnoreEnumWithMatchingItem("SDL_FALSE");
ctx.IgnoreEnumWithMatchingItem("DUMMY_ENUM_VALUE");
ctx.SetNameOfEnumWithMatchingItem("SDL_SCANCODE_UNKNOWN", "ScanCode");
ctx.SetNameOfEnumWithMatchingItem("SDLK_UNKNOWN", "Key");
ctx.SetNameOfEnumWithMatchingItem("KMOD_NONE", "KeyModifier");
ctx.SetNameOfEnumWithMatchingItem("SDL_LOG_CATEGORY_CUSTOM", "LogCategory");
ctx.GenerateEnumFromMacros("InitFlags", "SDL_INIT_(.*)").SetFlags();
ctx.GenerateEnumFromMacros("Endianness", "SDL_(.*)_ENDIAN");
ctx.GenerateEnumFromMacros("InputState", "SDL_RELEASED", "SDL_PRESSED");
ctx.GenerateEnumFromMacros("AlphaState", "SDL_ALPHA_(.*)");
ctx.GenerateEnumFromMacros("HatState", "SDL_HAT_(.*)");
ctx.IgnoreHeadersWithName("SDL_atomic*");
ctx.IgnoreHeadersWithName("SDL_endian*");
ctx.IgnoreHeadersWithName("SDL_main*");
ctx.IgnoreHeadersWithName("SDL_mutex*");
ctx.IgnoreHeadersWithName("SDL_stdinc*");
ctx.IgnoreHeadersWithName("SDL_error");
ctx.IgnoreEnumWithMatchingItem("SDL_ENOMEM");
ctx.IgnoreFunctionWithName("SDL_Error");
}
public void Postprocess(Driver driver, ASTContext ctx)
{
ctx.SetNameOfEnumWithName("PIXELTYPE", "PixelType");
ctx.SetNameOfEnumWithName("BITMAPORDER", "BitmapOrder");
ctx.SetNameOfEnumWithName("PACKEDORDER", "PackedOrder");
ctx.SetNameOfEnumWithName("ARRAYORDER", "ArrayOrder");
ctx.SetNameOfEnumWithName("PACKEDLAYOUT", "PackedLayout");
ctx.SetNameOfEnumWithName("PIXELFORMAT", "PixelFormats");
ctx.SetNameOfEnumWithName("assert_state", "AssertState");
ctx.SetClassBindName("assert_data", "AssertData");
ctx.SetNameOfEnumWithName("eventaction", "EventAction");
ctx.SetNameOfEnumWithName("LOG_CATEGORY", "LogCategory");
}
public static string GetExamplesDirectory(string name)
{
var directory = Directory.GetParent(Directory.GetCurrentDirectory());
while (directory != null)
{
var path = Path.Combine(directory.FullName, "examples", name);
if (Directory.Exists(path))
return path;
directory = directory.Parent;
}
throw new Exception(string.Format(
"Examples directory for project '{0}' was not found", name));
}
static class Program
{
public static void Main(string[] args)
{
ConsoleDriver.Run(new SDL());
}
}
}
}