36 lines
1.1 KiB
Zig
36 lines
1.1 KiB
Zig
const MyCharacter = struct {
|
|
pub var API = machinery.Interface(@This()).VTable;
|
|
|
|
x: u32 = 0,
|
|
y: u32 = 0,
|
|
z: u32 = 0,
|
|
|
|
// any function with 'self' as an argument is automatically added to the InterfaceVTable
|
|
// shit.. do i need to make a way to generate a struct from the arguments to the
|
|
// function?
|
|
pub fn add(self: *@This(), new: u32) void {
|
|
self.z = self.x + self.y + new;
|
|
}
|
|
|
|
// any error functions called through the api wrapper has it's errors wrapped and narrowed,
|
|
// and logged
|
|
pub fn sub(self: *@This()) void {
|
|
self.z = self.x - self.y;
|
|
}
|
|
|
|
pub fn callMyOwnInterfaces() void {
|
|
machinery.call(API, "add", .{ .new = 32 });
|
|
// could add a helper inside API that just aliases to machinery.call
|
|
API.call("add", .{ .new = 32 });
|
|
}
|
|
};
|
|
|
|
const SomeOtherModule = struct {
|
|
// if this was another file id do
|
|
// const MyCharacter = @import("MyCharacterApi").API;
|
|
const MyCharacterApi = MyCharacter.API;
|
|
pub var API = machinery.Interface(@This()).VTable;
|
|
};
|
|
|
|
const machinery = @import("machinery");
|