forked from natecraddock/ziglua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluau-bytecode.zig
More file actions
35 lines (27 loc) · 986 Bytes
/
Copy pathluau-bytecode.zig
File metadata and controls
35 lines (27 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Run Luau bytecode
// How to recompile `test.luau.bin` bytecode binary:
//
// luau-compile --binary test.luau > test.bc
//
// This may be required if the Luau version gets upgraded.
const std = @import("std");
// The ziglua module is made available in build.zig
const ziglua = @import("ziglua");
pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
// Initialize The Lua vm and get a reference to the main thread
//
// Passing a Zig allocator to the Lua state requires a stable pointer
var lua = try ziglua.Lua.init(&allocator);
defer lua.deinit();
// Open all Lua standard libraries
lua.openLibs();
// Load bytecode
const src = @embedFile("./test.luau");
const bc = try ziglua.compile(allocator, src, ziglua.CompileOptions{});
defer allocator.free(bc);
try lua.loadBytecode("...", bc);
try lua.protectedCall(0, 0, 0);
}