robin/maivi

a tiny cute lua web framework

git clone https://git.robinwobin.dev/robin/maivi

robinrefactor: restructure modules3d0ef52

main
869 B29 linesraw
1const std = @import("std");
2
3const fern = @import("fern");
4const zlua = @import("zlua");
5pub const Lua = zlua.Lua;
6
7const maivi = @import("../root.zig");
8
9/// * Pops from Stack: `(args.args + 1)`
10/// * Pushes to Stack: `(args.results|1)`
11pub fn pcall(l: *Lua, args: Lua.ProtectedCallArgs) !void {
12    return l.protectedCall(args) catch |err| switch (err) {
13        error.LuaRuntime => {
14            const msg = try l.toString(-1);
15            l.pop(1);
16            l.traceback(l, msg, 1);
17            const str = try l.toString(-1);
18            l.pop(1);
19            const e = try maivi.allocator.dupe(u8, str);
20            defer maivi.allocator.free(e);
21            fern.err().ctx("lua.pcall").str("err", e).log();
22            return err;
23        },
24        else => {
25            fern.err().ctx("lua.pcall").err(err).log();
26            return err;
27        },
28    };
29}