Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 19 additions & 2 deletions test/midlevel.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand Down
Loading