Initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
const std = @import("std");
|
||||
const zluau = @import("luau");
|
||||
|
||||
const luau = @import("luau.zig");
|
||||
|
||||
const c = @cImport({
|
||||
@cInclude("../include/bridge.h");
|
||||
});
|
||||
|
||||
pub fn run(
|
||||
allocator: std.mem.Allocator,
|
||||
io: std.Io,
|
||||
name: [:0]const u8,
|
||||
source: []const u8,
|
||||
) !void {
|
||||
c.xsh_set_luau_flags();
|
||||
|
||||
var L = try zluau.init(&allocator);
|
||||
defer L.deinit();
|
||||
|
||||
try L.Lopenlibs();
|
||||
|
||||
try luau.init(L, io);
|
||||
|
||||
const bytecode = zluau.compile(
|
||||
allocator,
|
||||
source,
|
||||
.{},
|
||||
) catch |err| {
|
||||
std.debug.print(
|
||||
"xsh: failed to compile '{s}': {}\n",
|
||||
.{ name, err },
|
||||
);
|
||||
return err;
|
||||
};
|
||||
|
||||
defer allocator.free(bytecode);
|
||||
|
||||
// try L.load(name, bytecode, 0);
|
||||
L.load(name, bytecode, 0) catch |err| {
|
||||
const message = L.tostring(-1) orelse "unknown Luau load error";
|
||||
|
||||
std.debug.print(
|
||||
"xsh: failed to load '{s}': {s} ({})\n",
|
||||
.{ name, message, err },
|
||||
);
|
||||
|
||||
L.pop(1);
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
const call = L.pcall(0, 0, 0);
|
||||
|
||||
if (call.check()) |_| {
|
||||
return;
|
||||
} else |err| {
|
||||
const message = L.tostring(-1) orelse "unknown Luau runtime error";
|
||||
|
||||
std.debug.print(
|
||||
"xsh: {s}\n",
|
||||
.{message},
|
||||
);
|
||||
|
||||
L.pop(1);
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user