{
  "id": 12375267,
  "title": "Extend Lua with Zig 1: Hello World",
  "url": "https://urgent.news/2026/10/06/extend-lua-with-zig-1-hello-world",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-06T11:58:23.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://www.robbielyman.com/blog/extend-lua-with-zig-1/"
  },
  "original_language": "en",
  "account": "Recently, I had the chance to assist someone in getting started with Zig and Lua for the third or fourth time. This experience has led me to write a blog post about the process. In this post, I will assume that you are familiar with Lua basics and won't assume much about Zig. By the end of the series, I aim to have you running your own Zig function from Lua. Along the way, we will learn about Zig's syntax, its build system, and how to incorporate other Zig code into your programs.\n\nThe code examples in this blog post should work with both Zig 0.17 and the master branch. If you find any issues, please email me so I can update the post. First, let's run it. You can download a release build of Zig from Ziglang.org. I recommend installing Zig by downloading the appropriate tarball for your OS and architecture, then moving or symlinking the contents onto your path. If you prefer, your distribution may already have Zig packaged. To run the example, use the command zig run hello.zig in a terminal. Zig and Lua share many concepts, such as files implicitly being functions and files being compiled to run their \"script\" parts. In our Hello World program, we declare a constant scoped to the largest containing block, whose value is on the right-hand side of the = sign. The key difference is that Zig allows compiler builtins, which have special powers unlike regular functions. The @import() function is one such builtin, allowing you to match string literals to Zig source files in your project, dependencies, or the standard library. In Lua, loading a file runs its script parts, similar to how compiling a Zig file runs its script parts. To declare a constant in Zig, use const followed by the variable name and its value. In Lua, this would be done using a variable assignment. The @import() function in Zig is used to match string literals to source files, while in Lua, the require() function is used for this purpose, though it can be overwritten or implemented in userland. Zig code can be executed at compile time, following the rule that comptime code execution is eager, except when calling normal functions. In Lua, top-level scope is not a function, so procedural code cannot be run at that level. If you want to execute code at compile time, put it in a block. Unlike Lua, Zig requires naming functions, using fn before the function name and placing the return type after the arguments. In Lua, functions can be anonymous, but in Zig, declaring a function requires naming it.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}