# Extend Lua with Zig 1: Hello World

**URL:** <https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864>\
**Category:** Media\
**Created:** [October 6, 2026, 5:19am UTC](https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864 "2026-10-06T05:19:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanza](https://ziggit.dev/user_avatar/ziggit.dev/alanza/32/6006_2.png) [@alanza](https://ziggit.dev/u/alanza)\
**Post date:** [October 6, 2026, 5:19am UTC](https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864/1 "2026-10-06T05:19:07Z")

</div>

> **[Robbie Lyman](https://www.robbielyman.com/blog/extend-lua-with-zig-1/)**

I’m intending to write two or three posts in total, of which this is the first. In this post we write “Hello World!” and our first `build.zig` script. My goal for the next post or two is to depend on and use [Ziglua](https://github.com/natecraddock/ziglua) to write an executable that hosts Lua, and then a dynamic library which can be hosted by your system’s Lua interpreter.

One of the fun parts about putting Lua and Zig together is that (on the syntax level) you see a lot of common features. I put forward some ways you can think of Zig’s syntax as a bit like “ahead-of-time Lua”.

I wrote with approximately the same amount of random discursiveness that you’d get from me if we were pairing to do these tasks. So there are random asides and tangents and a bit more chatting than is necessary to accomplish the task.

Any feedback very welcome 🙂

---

<div class="post-metadata">

**Author:** ![Lygaen](https://ziggit.dev/user_avatar/ziggit.dev/lygaen/32/7197_2.png) [@Lygaen](https://ziggit.dev/u/Lygaen)\
**Post date:** [October 6, 2026, 5:56am UTC](https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864/2 "2026-10-06T05:56:14Z")

</div>

Oh nice !  
It seems a lot of minds converge on the usage of lua with zig !

I wtote a thin wrapper for lua 5.5 if you want to have a look (no AI whatsoever).

It’s not the most up to date code, as I’m using it for another (private) project so I update it only when needed.

[https://codeberg.org/mathieu\_cayeux/lua.zig](https://codeberg.org/mathieu_cayeux/lua.zig)

I implemented some nice features such as the ability to add public declarations / functions with only one functions (and the wrapper is created at comptime).

So you can do something like :

```zig
const std = @import("std");

const lua = @import("lua-zig");

fn functor(value: u32) u32 {
    std.log.debug("functor({})", .{value});

    return value * value;
}

const LUA_PROGRAM =
    \\function multiply(x, y)
    \\ local z = x * y
    \\ z = functor(z)
    \\ return z
    \\end
;

pub fn main(init: std.process.Init) !void {
    var state: lua.Lua = try .init(init.gpa, .{});
    defer state.deinit();
    defer {
        if (state.diag.hasErr()) {
            std.log.err("{}: {s}", .{ state.diag.err.?, state.diag.message });
        }
    }

    try state.setGlobal("functor", functor);

    const reader = std.Io.Reader.fixed(LUA_PROGRAM);
    try state.loadFromReader(reader);
    // The program must be ran once to load symbols
    try state.run();

    const ret = try state.call("multiply", .{ 2, 3 }, u32);

    std.log.debug("functor(2 * 3) = {}", .{ret});
}

```

I definitely had the same Lua-JIT feeling that you had !

Nice one !

---

<div class="post-metadata">

**Author:** ![natecraddock](https://ziggit.dev/user_avatar/ziggit.dev/natecraddock/32/3012_2.png) [@natecraddock](https://ziggit.dev/u/natecraddock)\
**Post date:** [October 6, 2026, 3:41pm UTC](https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864/3 "2026-10-06T15:41:13Z")

</div>

Looking forward to the other posts! I’ve had a lot of thoughts on how Lua and Zig are similar so it was nice to see it put into words. Maybe this would be something nice to link to from the Ziglua docs/readme once it’s all written.

One note, the blog post year is 2027.

---

<div class="post-metadata">

**Author:** ![yrds96](https://ziggit.dev/user_avatar/ziggit.dev/yrds96/32/9837_2.png) [@yrds96](https://ziggit.dev/u/yrds96)\
**Post date:** [October 6, 2026, 7:45pm UTC](https://ziggit.dev/t/extend-lua-with-zig-1-hello-world/17864/4 "2026-10-06T19:45:43Z")

</div>

Great read! I want to add some lua to a project, so I’m really interested in the subject.

> [@alanza](#):
>
> I wrote with approximately the same amount of random discursiveness that you’d get from me if we were pairing to do these tasks. So there are random asides and tangents and a bit more chatting than is necessary to accomplish the task.

Not that that’s is a bad thing.

> Lua will run both of these statemnts.

Minor spelling mistake.
