From e91c88fd0922bc59424a7449124412d565bde087 Mon Sep 17 00:00:00 2001
From: tri <tri@thac.loan>
Date: Sun, 12 Oct 2025 14:47:52 +0700
Subject: [PATCH] add option to dynamically link lua

---
 Makefile  |  4 +++-
 build.zig |  6 ++++++
 readme.md | 14 ++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 87612c5..bc33da5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
+ZIGARGS = -Doptimize=ReleaseSafe -Dcpu=baseline -fsys=lua
+
 build:
-	zig build -Doptimize=ReleaseSafe
+	zig build $(ZIGARGS)
 
 watch:
 	zig build run --watch -- sample
diff --git a/build.zig b/build.zig
index c909164..250e7de 100644
--- a/build.zig
+++ b/build.zig
@@ -14,10 +14,16 @@ pub fn build(b: *std.Build) void {
 
     b.installArtifact(exe);
 
+    const use_system_lua = b.systemIntegrationOption("lua", .{});
+
     const lua_dep = b.dependency("zlua", .{
         .target = target,
         .optimize = optimize,
+        .shared = use_system_lua,
     });
+    if (use_system_lua) {
+        exe.linkSystemLibrary("lua");
+    }
     exe.root_module.addImport("zlua", lua_dep.module("zlua"));
 
     const run_step = b.step("run", "Run the app");
diff --git a/readme.md b/readme.md
index 6dd9cca..63cb63e 100644
--- a/readme.md
+++ b/readme.md
@@ -36,6 +36,18 @@ loa
 loa .
 ````
 
+## Build
+
+Loa targets zig 0.15.1 and by default has no runtime dependency except for libc. You can optionally dynamically link lua 5.4 with `-fsys=lua`.
+
+```sh
+# either command works:
+zig build -Doptimize=ReleaseSafe
+zig build -Doptimize=ReleaseSafe -fsys=lua
+```
+
+If you're curious, lua is used for running [djot.lua][1], which is vendored in src/vendor/djot.lua.
+
 ## License
 
 Copyright © 2025 tri@thac.loan
@@ -45,3 +57,5 @@ This program is free software: you can redistribute it and/or modify it under th
 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 
 You should have received a copy of the GNU Affero General Public License along with this program (agpl-3.0.txt). If not, see <https://www.gnu.org/licenses/>.
+
+[1]: https://github.com/jgm/djot.lua
-- 
2.47.3

