vibrantrida/mruby-zig
mruby 3.3.0 bindings for zig 0.12.0
Mruby is the lightweight implementation of the Ruby language complying with part of the ISO standard.
Mruby documentation can be found here.
I encountered some quirks when building on Windows (Powershell) so I had to remove the setting of
environment variables from build.zig
, now you have to set it manually so before anything else be
sure to set the following environment variables temporarily
# Windows - Powershell
$Env:CC = zig cc
$Env:CXX = zig c++
$Env:AR = zig ar
# *nix
CC = zig cc
CXX = zig c++
AR = zig ar
If that doesn't work, use absolute path
To embed mruby
into another zig project, you just need to
recursively clone this repository and add a couple of lines to your
build.zig
.
build.zig
, with the paths changed to match the correct locationconst addMruby = @import("mruby-zig/build.zig").addMruby;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
addMruby(target, b, exe);
// ...
}
mruby
and start a new interpreterconst std = @import("std");
const mruby = @import("mruby");
pub fn main() anyerror!void {
// Opening a state
var mrb = try mruby.open();
defer mrb.close();
// Loading a program from a string
_ = mrb.load_string("puts 'hello from ruby!'");
}
See examples/main.zig