Creating Lua modules (aka Neovim plugins) with Zig

If you’re a Neovim user like myself, and love tinkering with your Neovim configs in Lua, you might have wondered - can I write a Neovim plugin in Zig? Well, the answer is yes! The Lua C API is quite elegant, and as it turns out, it’s extremely easy to create a shared library compatible with Lua using Zig.

Check out a complete (but minimal) example on my Github here.

And if you’re wondering, why bother? Well, my end goal is to connect my (WIP) Markdown parser and renderer with Neovim to get a sort of VSCode-style “Preview Pane” plugin. Of course, the simple option is to just compile it as an executable and run it via a system command, but the thought of a tight integration sounds :ok_hand:

16 Likes

There is more important (from my point of the view) use case -
Scripting with Lua
I hope in the future will be number of Zig servers/brokers/etc and customization via Lua may be important

1 Like

This is a helpful post. I’ll look into using your guide to neovim plugins. I have some similar ambitions myself.

    pub fn eatLine(self: *Lexer) bool {
        const end_opt: ?usize = std.mem.indexOfScalarPos(u8, self.data, self.cursor, '\n');
        if (end_opt) |end| {
            self.cursor = end + 1;
            self.row.row += 1;
            self.src.col = 0;
            return true;
        } else {
            self.cursor = self.data.len;
            return false;
        }
    }

cat-eat-chips-chips

2 Likes