I need help to create bindings for OBS plugin API

I didn’t found any projects for OBS on zig, so I must do it myself. The idea now is to create bindings, so they’re will be used in my multichat plugin.
Dependencies can be found there https://github.com/obsproject/obs-plugintemplate.
Docs for Plugin API: https://docs.obsproject.com/plugins.
While I’ve tried translate-c, it returned lots of @compileError

P.S.: I didn’t have a deal with integration of Clang code into Zig myself, so any guides will be very helpful

Hi @liponex, welcome to Ziggit :slight_smile:

Most of the time, there is no problem with them. If you ever use anything from the problematic definitions you get the compile time error, until then you can ignore them.

A hint: find a very simple example and try to convert it in zig and build it, first without a build file.
e.g. zig build-lib myplugin.zig -lobs

1 Like

Thanks a lot! I’ve tried a few things. As I found in case of OBS plugin API, @cImport/@cInclude perfectly do their job, except few macros.
For other who’ll want to repeat this, I’ll recommend to go in libobs sources and re-write some macros to Zig, especially OBS_DECLARE_MODULE().
Simple example on Zig:

const obs_module = @cImport(@cInclude("obs/obs-module.h"));
const obs_config = @cImport(@cInclude("obs/obs-config.h"));
const obs_util_base = @cImport(@cInclude("obs/util/base.h"));

const obs_module_t = extern struct {};
var obs_module_pointer: ?*obs_module_t = null;
export fn obs_module_set_pointer(module: ?*obs_module_t) void {
    obs_module_pointer = module;
export fn obs_current_module() ?*obs_module_t {
    return obs_module_pointer;
export fn obs_module_ver() u32 {
    return obs_config.LIBOBS_API_VER;

// Plugin loading
export fn obs_module_load() bool {
    const PLUGIN_VERSION = "<Your version here>";
    obs_util_base.blog(obs_module.LOG_INFO, "plugin loaded successfully (version %s)", PLUGIN_VERSION);
    return true;

export fn obs_module_unload() void {
    obs_util_base.blog(obs_module.LOG_INFO, "plugin unloaded");