From d056b3ea8ceda623da4fea0511048ff220e48e56 Mon Sep 17 00:00:00 2001 From: "carpentry-heartbeat[bot]" Date: Mon, 1 Jun 2026 13:13:00 +0200 Subject: [PATCH] Add Luax.set-string-global for API consistency The set-*-global family had int, float, and bool variants but was missing string. This adds the missing macro expansion and tests. --- lua.carp | 1 + test/midlevel.carp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lua.carp b/lua.carp index 08ea5dd..bf398ae 100644 --- a/lua.carp +++ b/lua.carp @@ -523,6 +523,7 @@ and assigns it to a global in one expression: (luax--def-set-global int Lua.push-int) (luax--def-set-global float Lua.push-float) (luax--def-set-global bool Lua.push-bool) + (luax--def-set-global string Lua.push-carp-str) ; === get-*-global family === (luax--def-get-global int Lua.TYPE_NUMBER Lua.get-int "an integer" "a number") diff --git a/test/midlevel.carp b/test/midlevel.carp index 839ee42..c081f77 100644 --- a/test/midlevel.carp +++ b/test/midlevel.carp @@ -215,6 +215,23 @@ (Lua.get-bool lua -1)) "set-bool-global sets a boolean global") + ; === set-string-global === + (assert-true test + (= @"hello" + (Lua.with-lua-do (Lua.libs lua) + (Luax.set-string-global lua "s" "hello") + (Lua.get-global lua (cstr "s")) + (String.from-cstr-or (Lua.to-string lua -1) @""))) + "set-string-global sets a string global") + (assert-true test + (= @"world" + (Lua.with-lua-do (Lua.libs lua) + (Luax.set-string-global lua "greeting" "world") + (ignore (Lua.do-string lua (cstr "result = greeting"))) + (Lua.get-global lua (cstr "result")) + (String.from-cstr-or (Lua.to-string lua -1) @""))) + "string globals set from Carp are usable in Lua expressions") + ; === get-int-global === (assert-true test (= &(Maybe.Just 42) @@ -229,7 +246,7 @@ (assert-true test (Maybe.nothing? &(Lua.with-lua-do (Lua.libs lua) - (Lua.set-string-global lua "s" "hello") + (Luax.set-string-global lua "s" "hello") (Luax.get-int-global lua "s"))) "get-int-global returns Nothing for wrong type") @@ -259,7 +276,7 @@ (assert-true test (= &(Maybe.Just @"hello") &(Lua.with-lua-do (Lua.libs lua) - (Lua.set-string-global lua "s" "hello") + (Luax.set-string-global lua "s" "hello") (Luax.get-string-global lua "s"))) "get-string-global returns Just for existing string") (assert-true test