diff options
| author | bfredl <bjorn.linse@gmail.com> | 2026-04-21 20:09:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-21 20:09:57 +0200 |
| commit | fe6026825883b44b09a8d3a03f2d49bfc8ed4725 (patch) | |
| tree | a1ca487ce6912e9a7fd836f53cb4b6836a79e1e7 /src | |
| parent | 5891f2f3dc41eda44c0072d726cf95e54aba85ad (diff) | |
| parent | 52693e7af3d3c7445761c8c0644ca437d2bf2df6 (diff) | |
Merge pull request #39076 from bfredl/zig0.16
IT IS HAPPENING: Zig 0.16
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_lua.zig | 39 | ||||
| -rw-r--r-- | src/gen/gen_steps.zig | 7 | ||||
| -rw-r--r-- | src/nlua0.zig | 28 |
3 files changed, 43 insertions, 31 deletions
diff --git a/src/build_lua.zig b/src/build_lua.zig index 3d9b634ab1..a27fe01360 100644 --- a/src/build_lua.zig +++ b/src/build_lua.zig @@ -4,6 +4,7 @@ const LazyPath = std.Build.LazyPath; pub fn build_nlua0( b: *std.Build, + io: std.Io, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, use_luajit: bool, @@ -59,7 +60,7 @@ pub fn build_nlua0( mod.addIncludePath(b.path("src")); mod.addIncludePath(b.path("src/includes_fixmelater")); - try add_lua_modules(b, target.result, mod, lpeg, use_luajit, true, system_integration_options); + try add_lua_modules(b, io, target.result, mod, lpeg, use_luajit, true, system_integration_options); } // for debugging the nlua0 environment @@ -83,6 +84,7 @@ pub fn build_nlua0( pub fn add_lua_modules( b: *std.Build, + io: std.Io, target: std.Target, mod: *std.Build.Module, lpeg_dep: ?*std.Build.Dependency, @@ -110,7 +112,7 @@ pub fn add_lua_modules( .flags = &flags, }); if (system_integration_options.lpeg) { - if (try findLpeg(b, target)) |lpeg_lib| { + if (try findLpeg(b, io, target)) |lpeg_lib| { mod.addLibraryPath(.{ .cwd_relative = std.fs.path.dirname(lpeg_lib).? }); mod.addObjectFile(.{ .cwd_relative = lpeg_lib }); } @@ -149,33 +151,34 @@ pub fn build_libluv( ) !*std.Build.Step.Compile { const upstream = b.lazyDependency("luv", .{}); const compat53 = b.lazyDependency("lua_compat53", .{}); + var root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + }); const lib = b.addLibrary(.{ .name = "luv", .linkage = .static, - .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, - }), + .root_module = root_module, }); if (lua) |lua_lib| { - lib.root_module.linkLibrary(lua_lib); + root_module.linkLibrary(lua_lib); } else { const system_lua_lib = if (use_luajit) "luajit" else "lua5.1"; - lib.root_module.linkSystemLibrary(system_lua_lib, .{}); + root_module.linkSystemLibrary(system_lua_lib, .{}); } - lib.linkLibrary(libuv); + root_module.linkLibrary(libuv); if (upstream) |dep| { - lib.addIncludePath(dep.path("src")); + root_module.addIncludePath(dep.path("src")); lib.installHeader(dep.path("src/luv.h"), "luv/luv.h"); - lib.addCSourceFiles(.{ .root = dep.path("src/"), .files = &.{ + root_module.addCSourceFiles(.{ .root = dep.path("src/"), .files = &.{ "luv.c", } }); } if (compat53) |dep| { - lib.addIncludePath(dep.path("c-api")); - lib.addCSourceFiles(.{ .root = dep.path("c-api"), .files = &.{ + root_module.addIncludePath(dep.path("c-api")); + root_module.addCSourceFiles(.{ .root = dep.path("c-api"), .files = &.{ "compat-5.3.c", } }); } @@ -183,7 +186,7 @@ pub fn build_libluv( return lib; } -fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 { +fn findLpeg(b: *std.Build, io: std.Io, target: std.Target) !?[]const u8 { const filenames = [_][]const u8{ "lpeg_a", "lpeg", @@ -197,7 +200,7 @@ fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 { "--variable=pc_system_libdirs", "--keep-system-cflags", "pkg-config", - }, &code, .Ignore), "\r\n"); + }, &code, .ignore), "\r\n"); var paths: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 0); var path_it = std.mem.tokenizeAny(u8, dirs_stdout, " ,"); while (path_it.next()) |dir| { @@ -205,10 +208,10 @@ fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 { try paths.append(b.allocator, b.fmt("{s}/lua/5.1", .{dir})); } for (paths.items) |path| { - var dir = std.fs.openDirAbsolute(path, .{}) catch continue; - defer dir.close(); + var dir = std.Io.Dir.openDirAbsolute(io, path, .{}) catch continue; + defer dir.close(io); for (filenames) |filename| { - dir.access(filename, .{}) catch continue; + dir.access(io, filename, .{}) catch continue; return b.fmt("{s}/{s}", .{ path, filename }); } } diff --git a/src/gen/gen_steps.zig b/src/gen/gen_steps.zig index 794beb8df7..e0f4037641 100644 --- a/src/gen/gen_steps.zig +++ b/src/gen/gen_steps.zig @@ -5,6 +5,7 @@ pub const SourceItem = struct { name: []u8, api_export: bool }; pub fn nvim_gen_sources( b: *std.Build, + io: std.Io, nlua0: *std.Build.Step.Compile, nvim_sources: *std.ArrayList(SourceItem), nvim_headers: *std.ArrayList([]u8), @@ -85,15 +86,15 @@ pub fn nvim_gen_sources( } // Dynamically add all Lua _core/ modules (like CMakeLists.txt does) - if (b.build_root.handle.openDir("runtime/lua/vim/_core", .{ .iterate = true })) |core_dir_handle| { + if (b.build_root.handle.openDir(io, "runtime/lua/vim/_core", .{ .iterate = true })) |core_dir_handle| { var core_dir = core_dir_handle; - defer core_dir.close(); + defer core_dir.close(io); var iter = core_dir.iterate(); var core_files = try std.ArrayList([]const u8).initCapacity(b.allocator, 0); defer core_files.deinit(b.allocator); - while (try iter.next()) |entry| { + while (try iter.next(io)) |entry| { if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".lua")) { const module_name = try b.allocator.dupe(u8, entry.name[0 .. entry.name.len - 4]); try core_files.append(b.allocator, module_name); diff --git a/src/nlua0.zig b/src/nlua0.zig index cdd30506b5..3222a58c52 100644 --- a/src/nlua0.zig +++ b/src/nlua0.zig @@ -22,7 +22,7 @@ extern "c" fn luaopen_lpeg(ptr: *anyopaque) c_int; extern "c" fn luaopen_bit(ptr: *anyopaque) c_int; extern "c" fn luaopen_luv(ptr: *anyopaque) c_int; -fn init() !*Lua { +fn init_lua() !*Lua { // Initialize the Lua vm var lua = try Lua.init(std.heap.c_allocator); lua.openLibs(); @@ -69,26 +69,34 @@ fn init() !*Lua { return lua; } -pub fn main() !void { - const argv = std.os.argv; +pub fn main(init: std.process.Init) !void { + const args = init.minimal.args; - const lua = try init(); + const lua = try init_lua(); defer lua.deinit(); - if (argv.len < 2) { + if (args.vector.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.createTable(@intCast(args.vector.len - 2), 1); + + var iter = try init.minimal.args.iterateAllocator(init.arena.allocator()); + _ = iter.skip(); + var i: u32 = 0; + var firstarg: [:0]const u8 = undefined; + while (iter.next()) |val| : (i += 1) { + _ = lua.pushString(val); + if (i == 0) { + firstarg = try lua.toString(-1); // preserved on lua heap.. + } lua.rawSetIndex(-2, @intCast(i)); } lua.setGlobal("arg"); _ = try lua.getGlobal("debug"); _ = lua.getField(-1, "traceback"); - try lua.loadFile(std.mem.span(argv[1])); + try lua.loadFile(firstarg); lua.protectedCall(.{ .msg_handler = -2 }) catch |e| { if (e == error.LuaRuntime) { const msg = try lua.toString(-1); @@ -104,7 +112,7 @@ fn do_ret1(lua: *Lua, str: [:0]const u8) !void { } test "simple test" { - const lua = try init(); + const lua = try init_lua(); defer lua.deinit(); try do_ret1(lua, "return vim.isarray({2,3})"); |
