Modules ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
In the Zig language, a module is actually a struct without any fields. Only declarations of constants, variables, and functions. Since the object representing a struct type behaves like a PHP class, you can think of declarations within a module as static members.
Zigar exports all public declarations in a module using its own mechanism. You do not need to
use the export keyword.
const std = @import("std");
pub const pi = std.math.pi;
pub var number: i33 = 123;
pub fn hello() void {
std.debug.print("Hello world", .{});
}
<?php
$m = zigar_use(__DIR__ . '/module-example-1.zig');
echo "$m->pi\n";
echo "$m->number\n";
$m->hello();
3.1415926535898
123
Hello world
Exposing sub-modules
Since modules are structs, you can make a sub-module available simply by assigning it to a public constant in the root module:
const std = @import("std");
pub const example1 = @import("./module-example-1.zig");
<?php
$m = zigar_use(__DIR__ . '/module-example-2.zig');
$m->example1->hello();
Hello world