/ziglo

zig interface to liblo's OSC server implementation

Primary LanguageZigGNU Lesser General Public License v2.1LGPL-2.1

ziglo

ziglo is a Zig interface to liblo, an implementation of the Open Sound Control protocol. ziglo provides Zig types for liblo primitives and convenience functions for adding and querying message contents leveraging Zig’s comptime.

To add this package to your project, pick a commit hash <hash> and run this:

$ zig fetch --save https://github.com/ryleelyman/ziglo/archive/<hash>.tar.gz

Then in your build.zig you can add this:

const ziglo = b.dependency("ziglo", .{
    .target = target,
    .optimize = optimize,
    .static = true, // builds a static liblo; defaults to false
});

// For whatever you're building; in this case let's assume it's called exe.
exe.root_module.addImport("ziglo", ziglo.module("ziglo"));

and in your source code:

// import
const ziglo = @import("ziglo");

// and use it something like this...
const server = ziglo.Server.new(null, null) orelse return error.Failed;
defer server.free();
// can hold onto the opaque pointer returned if you want to later remove this method.
_ = server.addMethod("/an/osc/path", null, wrap(anOscMethodHandler), null) orelse return error.Failed;

const target = ziglo.Address.new("localhost", "7777") orelse return error.Failed;
defer target.free();

const msg = ziglo.Message.new() orelse return error.Failed;
defer msg.free();
msg.add(.{ 4, 4.5, "a string", .nil, .infinity, null, true, false });

try server.send(target, "/another/osc/path", msg);