aboutsummaryrefslogtreecommitdiff
path: root/src/interface.zig
blob: 530d8cf193ea07c224b23f47c8ee0d34fda51f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const std = @import("std");

const PluginCallbacks001 = @import("interfaces/PluginCallbacks001.zig").plugin_interface;
const PluginId001 = @import("interfaces/PluginId001.zig").plugin_interface;

pub const interfaces = .{
    PluginCallbacks001,
    PluginId001,
};

pub const InterfaceStatus = enum(c_int) {
    IFACE_OK = 0,
    IFACE_FAILED,
};

pub export fn CreateInterface(name_ptr: [*:0]const u8, status_ptr: ?*InterfaceStatus) callconv(.C) *allowzero void {
    const name = std.mem.span(name_ptr);

    inline for (interfaces) |interface| {
        if (std.mem.eql(u8, interface.name, name)) {
            if (status_ptr) |status| {
                status.* = .IFACE_OK;
            }

            return interface.func();
        }
    }

    if (status_ptr) |status| {
        status.* = .IFACE_FAILED;
    }

    return @ptrFromInt(0);
}