Backlog/engine/core/tests/externalModule.zig

29 lines
1.0 KiB
Zig

var gAllocator: std.mem.Allocator = undefined;
pub export fn startup_module(p_allocator: *anyopaque, args: ?*anyopaque) bool {
const allocator = core.modulePreamble(p_allocator, args) catch return false;
// do some test allocations and let it leak
const t = std.fmt.allocPrint(allocator, "Lmao 2 nova {d}", .{2}) catch unreachable;
std.debug.print("external module started allocated string: {s}\n", .{t});
allocator.free(t);
const subsystem = core.get(SampleSubsystem);
SceneAPI.setPosition = @ptrCast(@alignCast(subsystem.setPositionPtr));
const a: SceneAPI.setPositionArgs = .{ subsystem.scene, core.Vectorf{ .y = 12, .z = 13 } };
const argsAsBytes = std.mem.asBytes(&a);
machinery.callInner(SceneAPI.setPosition, argsAsBytes);
return true;
}
pub export fn shutdown_module() void {}
const hand = @import("SceneApiHand.zig");
const SceneAPI = hand.SceneAPI;
const SampleSubsystem = @import("samplesubsystem.zig");
const core = @import("core");
const std = @import("std");
const machinery = core.machinery;