Something went wrong. Try again.
🦦 a tiny cute lua web framework
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364const fern = @import("fern");const zlua = @import("zlua");pub const Lua = zlua.Lua;
const maivi = @import("../root.zig");
pub fn lua_print(l: *Lua) !i32 { var logger = fern.info().ctx("lua.print"); defer logger.log();
l.pushValue(-1);
if (l.isTable(-1)) { l.pushNil(); // stack now contains: -1 => nil; -2 => table while (l.next(-2)) { // stack now contains: -1 => value; -2 => key; -3 => table // copy the key so that toString does not modify the original l.pushValue(-2); // stack now contains: -1 => key; -2 => value; -3 => key; -4 => table const kz = try l.toString(-1); const vz = l.toString(-2) catch vz: { break :vz l.typeNameIndex(-2); }; logger = logger.str(kz, vz); // pop value + copy of key, leaving original key l.pop(2); // stack now contains: -1 => key; -2 => table } } else { const str = try l.toString(-1); l.pop(1); const s = try maivi.allocator.dupe(u8, str); defer maivi.allocator.free(s); logger = logger.str("v", s); }
l.pop(1);
return 0;}
// fn get_keys(l: *zlua.Lua, keys: *std.ArrayList([]const u8)) !void {// l.pushValue(-1);//// if (!l.isTable(-1)) return error.NotATable;//// l.pushNil();// // stack now contains: -1 => nil; -2 => table// while (l.next(-2)) {// // stack now contains: -1 => value; -2 => key; -3 => table// // copy the key so that toString does not modify the original// l.pushValue(-2);// // stack now contains: -1 => key; -2 => value; -3 => key; -4 => table// const kz = try l.toString(-1);// keys.appendBounded(kz) catch continue;// // pop value + copy of key, leaving original key// l.pop(2);// // stack now contains: -1 => key; -2 => table// }//// l.pop(1);// }