Compare commits

..

2 Commits

Author SHA1 Message Date
91ddcd4f79 improve README 2026-06-07 19:14:45 +02:00
a8150171fc add README 2026-06-07 19:06:09 +02:00

72
README.md Normal file
View File

@@ -0,0 +1,72 @@
# 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
1. Create a `Setup` workspace and add Cpp2Beef from remote (`https://git.unicon-gmbh.de/Rune/Cpp2Beef.git`)
2. Add Cpp2Beef as a dependency
3. Write your generator
```beef
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
}
// Create a single header file that includes all other header files and then call Generate once
// This is significanly faster than calling Generate for each header file because of header guards
scope ExampleGenerator(char8*[?]("--language=c", "-DSOMETHING")).Generate("example.h");
```