robin/maivi

a tiny cute lua web framework

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

robinmaivi: proper io usage6e07b35

main
698 B25 linesraw
1const maivi = @import("../root.zig");
2const Connection = maivi.handler.Connection;
3const helpers = maivi.helpers;
4const lua = @import("root.zig");
5const Lua = lua.Lua;
6
7pub fn lua_read(l: *Lua) !i32 {
8    l.argCheck(l.isString(1), 1, "string");
9    const pathz = try l.toString(-1);
10
11    const path = try maivi.allocator.dupe(u8, pathz);
12    defer maivi.allocator.free(path);
13
14    const conn = blk: {
15        _ = l.getGlobal("ctx");
16        const ltype_ptr = l.getField(-1, "ptr");
17        defer l.pop(1);
18        if (ltype_ptr != .light_userdata) return error.InvalidPtr;
19        break :blk try l.toUserdata(Connection, -1);
20    };
21
22    try maivi.lua.read_data(l, conn.io, path);
23
24    return 1;
25}