Repository: neovim/neovim
File: src/nlua0.zig (Zig)

Code before:

    try lua.loadBuffer(embedded_data.iter_module, "iter.lua");
    lua.call(.{ .results = 1 });
    lua.setField(-2, "iter");

    _ = try lua.getGlobal("package");
    _ = lua.getField(-1, "preload");
    try lua.loadBuffer(hashy, "hashy.lua"); // [package, preload, hashy]
    lua.setField(-2, "gen.hashy");
    try lua.loadBuffer(c_grammar, "c_grammar.lua"); // [package, preload, c_grammar]
    lua.setField(-2, "gen.c_grammar");
    lua.pop(2);

    const retval = luaopen_mpack(lua);
    if (retval != 1) return error.LoadError;
    _ = lua.getField(-1, "NIL"); // [vim, mpack, NIL]
    lua.setField(-3, "NIL"); // vim.NIL = mpack.NIL (wow BOB wow)
    lua.setField(-2, "mpack");

    const retval2 = luaopen_lpeg(lua);
    if (retval2 != 1) return error.LoadError;
    lua.setField(-3, "lpeg");

    // vim.text.diff
    lua.pushFunction(nlua_xdl_diff);
    lua.setField(-2, "_diff");

    lua.pop(2);

    if (!options.use_luajit) {
        lua.pop(luaopen_bit(lua));
    }
    return lua;
}

pub fn main() !void {
    const argv = std.os.argv;

    const lua = try init();
    defer lua.deinit();

    if (argv.len < 2) {
        std.debug.print("USAGE: nlua0 script.lua args...\n\n", .{});
        return;
    }
    lua.createTable(@intCast(argv.len - 2), 1);
    for (0.., argv[1..]) |i, arg| {
        _ = lua.pushString(std.mem.span(arg));
        lua.rawSetIndex(-2, @intCast(i));
    }
    lua.setGlobal("arg");

Review comment (suggestion):
idk

```
src/nlua0.zig:61:22: error: expected type '*const fn (?*luajit_all.struct_lua_State) callconv(.c) c_int', found '*const fn (*anyopaque) callconv(.c) c_int'
    lua.pushFunction(nlua_xdl_diff);
                     ^~~~~~~~~~~~~
src/nlua0.zig:61:22: note: pointer type child 'fn (*anyopaque) callconv(.c) c_int' cannot cast into pointer type child 'fn (?*luajit_all.struct_lua_State) callconv(.c) c_int'
```

Code after:
    try lua.loadBuffer(embedded_data.iter_module, "iter.lua");
    lua.call(.{ .results = 1 });
    lua.setField(-2, "iter");

    _ = try lua.getGlobal("package");
    _ = lua.getField(-1, "preload");
    try lua.loadBuffer(hashy, "hashy.lua"); // [package, preload, hashy]
    lua.setField(-2, "gen.hashy");
    try lua.loadBuffer(c_grammar, "c_grammar.lua"); // [package, preload, c_grammar]
    lua.setField(-2, "gen.c_grammar");
    lua.pop(2);

    const retval = luaopen_mpack(lua);
    if (retval != 1) return error.LoadError;
    _ = lua.getField(-1, "NIL"); // [vim, mpack, NIL]
    lua.setField(-3, "NIL"); // vim.NIL = mpack.NIL (wow BOB wow)
    lua.setField(-2, "mpack");

    const retval2 = luaopen_lpeg(lua);
    if (retval2 != 1) return error.LoadError;
    lua.setField(-3, "lpeg");

    lua.pop(2);

    if (!options.use_luajit) {
        lua.pop(luaopen_bit(lua));
    }
    return lua;
}

pub fn main() !void {
    const argv = std.os.argv;

    const lua = try init();
    defer lua.deinit();

    if (argv.len < 2) {
        std.debug.print("USAGE: nlua0 script.lua args...\n\n", .{});
        return;
    }
    lua.createTable(@intCast(argv.len - 2), 1);
    for (0.., argv[1..]) |i, arg| {
        _ = lua.pushString(std.mem.span(arg));
        lua.rawSetIndex(-2, @intCast(i));
    }
    lua.setGlobal("arg");

    _ = try lua.getGlobal("debug");
    _ = lua.getField(-1, "traceback");
    try lua.loadFile(std.mem.span(argv[1]));
    lua.protectedCall(.{ .msg_handler = -2 }) catch |e| {