srctree

Gregory Mullen parent 56289381 051d8e23
expose the module needed to be used as a library

build.zig added: 60, removed: 39, total 21
@@ -1,6 +1,6 @@
const std = @import("std");
const plugin_config = @import("src/root.zig").module_defaults;
const name = plugin_config.name;
const project_name = @import("src/root.zig").module_defaults.name;
const name = project_name;
 
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
@@ -22,8 +22,18 @@ pub fn build(b: *std.Build) void {
},
});
 
const module = b.addModule("OBS", .{
.root_source_file = .{
.path = "src/root.zig",
},
.target = target,
.optimize = optimize,
});
module.linkLibrary(shim);
//module.linkLibC();
 
const lib = b.addSharedLibrary(.{
.name = name,
.name = "obzig-plugin",
.root_source_file = .{
.path = "src/root.zig",
},
 
filename was Deleted added: 60, removed: 39, total 21
@@ -0,0 +1,26 @@
/// Module Info used to set up a plugin
pub const ModuleInfo = @This();
 
/// Name of the OBS plugin
name: [:0]const u8 = "Unnamed Module",
/// Current version of this plugin
version: [:0]const u8 = "0.0.0",
/// Author of the this plugin
author: [:0]const u8 = "Anonymous Authors",
/// Description for this plugin
description: [:0]const u8 = "Default Description for an unnamed module.",
 
/// Optional function that will be called when the plugin is loaded by OBS
/// this function does not require callconv(.C) but other call backs
/// provided may require it.
on_load_fn: *const fn () bool = empty_on_load,
/// Optional function that will be called when the plugin is unloaded by OBS
/// usually at program exit, but there are other events that could unload a
/// plugin.
on_unload_fn: *const fn () void = empty_on_unload,
 
fn empty_on_load() bool {
return true;
}
 
fn empty_on_unload() void {}
 
src/obs.zig added: 60, removed: 39, total 21
@@ -1,5 +1,6 @@
const std = @import("std");
const root = @import("root");
const ModuleInfo = @import("module-info.zig");
const bufPrintZ = std.fmt.bufPrintZ;
 
pub const OBS = @cImport({
@@ -15,27 +16,7 @@ pub const Scene = @import("obs/frontend.zig").OBSScene;
pub const QtShim = @import("obs/frontend.zig").QtShim;
 
/// Define a module_defaults in you root project file
const module_defaults: ModuleDefaults = if (@hasDecl(root, "module_defaults")) root.module_defaults else .{};
 
pub const ModuleDefaults = struct {
/// Name of the OBS plugin
name: [:0]const u8 = "Unnamed Module",
/// Current version of this plugin
version: [:0]const u8 = "0.0.0",
/// Author of the this plugin
author: [:0]const u8 = "Anonymous Authors",
/// Description for this plugin
description: [:0]const u8 = "Default Description for an unnamed module.",
 
/// Optional function that will be called when the plugin is loaded by OBS
/// this function does not require callconv(.C) but other call backs
/// provided may require it.
on_load_fn: *const fn () bool = empty_on_load,
/// Optional function that will be called when the plugin is unloaded by OBS
/// usually at program exit, but there are other events that could unload a
/// plugin.
on_unload_fn: *const fn () void = empty_on_unload,
};
const module_defaults: ModuleInfo = if (@hasDecl(root, "module_defaults")) root.module_defaults else .{};
 
/// call exportOBS in comptime to ensure Zig is able to see the required
/// funtions obs needs to export.
@@ -92,12 +73,6 @@ export fn obs_module_unload() void {
return module_defaults.on_unload_fn();
}
 
fn empty_on_load() bool {
return true;
}
 
fn empty_on_unload() void {}
 
pub fn logFmt(comptime text: []const u8, vars: anytype) void {
var buf: [0xffff:0]u8 = undefined;
const txt = bufPrintZ(&buf, text, vars) catch unreachable;
 
src/obs/frontend.zig added: 60, removed: 39, total 21
@@ -12,7 +12,7 @@ extern "obs-frontend-api" fn obs_frontend_get_scene_names() callconv(.C) [*:null
extern "obs-frontend-api" fn obs_frontend_get_scenes(?*obs_frontend_source_list) callconv(.C) void;
extern "obs-frontend-api" fn obs_frontend_preview_program_trigger_transition() callconv(.C) void;
//extern "obs-frontend-api" fn obs_frontend_source_list_free(?*obs_frontend_source_list) callconv(.C) void;
extern "obs-frontend-api" fn obs_frontend_add_dock(?*anyopaque) callconv(.C) void;
extern "obs-frontend-api" fn obs_frontend_add_custom_qdock([*c]const u8, ?*anyopaque) callconv(.C) bool;
extern "obs-frontend-api" fn obs_frontend_get_main_window() callconv(.C) ?*anyopaque;
 
const obs_frontend_cb = *const fn (?*anyopaque) callconv(.C) void;
@@ -78,9 +78,9 @@ pub const OBSScene = struct {
extern "qt_shim" fn createDock(?*anyopaque) callconv(.C) ?*anyopaque;
 
pub const QtShim = struct {
pub fn newDock() void {
pub fn newDock(name: [:0]const u8) bool {
const qtwin = obs_frontend_get_main_window();
const dock = createDock(qtwin);
obs_frontend_add_dock(dock);
return obs_frontend_add_custom_qdock(name.ptr, dock);
}
};
 
src/root.zig added: 60, removed: 39, total 21
@@ -2,8 +2,18 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const obs = @import("obs.zig");
//pub usingnamespace obs;
pub const ModuleInfo = @import("module-info.zig");
 
pub const module_defaults = .{
pub const logFmt = obs.logFmt;
pub const log = obs.log;
pub const Scene = @import("obs/frontend.zig").OBSScene;
pub const QtShim = @import("obs/frontend.zig").QtShim;
pub fn includeExports() void {
return obs.exportOBS();
}
 
pub const module_defaults: ModuleInfo = .{
.name = "Really-Cool-Zig-Plugin",
.version = "0.0.0",
.author = "grayhatter",