2.1 KiB
2.1 KiB
Cpp2Beef
Cpp2Beef is a library for writing high quality beef bindings for C and C-Style C++. Cpp2Beef does the heavy lifting so you can focus on the library specific stuff.
You can find bindings generated by Cpp2Beef at https://git.unicon-gmbh.de/BeefBindings.
Usage
- Create a
Setupworkspace and add Cpp2Beef from remote (https://git.unicon-gmbh.de/Rune/Cpp2Beef.git) - Add Cpp2Beef as a dependency
- Write your generator
class ExampleGenerator : Cpp2BeefGenerator, this(Span<char8*> args)
{
protected override Span<char8*> Args => args;
protected override Flags Flags => .None;
// You can have your binding in one file or in multiple, file management is up to you
StreamWriter writer = new .()..Create("../src/Example.bf")..Write("""
// This file was generated by Cpp2Beef
using System;
using System.Interop;
namespace Example;
""") ~ delete _;
protected override StreamWriter GetWriterForHeader(StringView header)
{
// Here you define the target file to which a cursor should be written
// Returning null skips the cursor
if (header.EndsWith("example.h"))
return writer;
return null;
}
protected override Block GetCursorBlock(CXCursor cursor)
{
// Optional. This can be used put cursors in custom blocks
// This is useful if you want all your functions to be a static class
if (cursor.kind == .FunctionDecl)
return .CustomBlock("Example");
return base.GetCursorBlock(cursor);
}
protected override void HandleCursor(CXCursor cursor)
{
// Optional. Can be used to write custom logic, how a cursor should be written
// If your going for this I'd recommend looking at examples in BeefBindings
base.HandleCursor(cursor);
}
protected override void WriteCustomAttributes(CXCursor cursor)
{
// Optional.
base.WriteCustomAttributes(cursor);
}
protected override void GetNameInBindings(LibClang.CXCursor cursor, String outString)
{
// Optional but you pretty much want to always override this.
// Allows you to change the name of cursors
base.GetNameInBindings(cursor, outString);
}
// There are functions you can override, but these are the most common
}