From 6d666451bf9386d2310801db8b26ff9923f61f6e Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Mon, 13 Oct 2025 15:11:17 -0400 Subject: [PATCH 1/6] lua global variable example --- lua/global_variables/global_variables.odin | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lua/global_variables/global_variables.odin diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin new file mode 100644 index 0000000..7a161e4 --- /dev/null +++ b/lua/global_variables/global_variables.odin @@ -0,0 +1,33 @@ +package main + +import lua "vendor:lua/5.4" +import "core:fmt" + +// The code the Lua VM will run +CODE :: "print(Answer)" + +main :: proc() { + // Create new Lua state + state := lua.L_newstate() + + // Open the base libraries (print, etc...) + lua.open_base(state) + + // Set a new global integer (a Lua 5.3+ feature!) called "answer" to 42 + // First we push the integer to the stack, which is our "postboard" to talk with the Lua VM + lua.pushinteger(state, 42) + // Pops the top value on the stack and creates a global with it's value + lua.setglobal(state, "Answer") + + // Run code and check if it succeeded + if (lua.L_dostring(state, CODE) != 0) { + // Get the error string from the top of the stack and print it + error := lua.tostring(state, -1) + fmt.println(error) + // Pop the error off of the stack + lua.pop(state, 1) + } + + // Closes the Lua VM, deallocating all memory + lua.close(state) +} \ No newline at end of file From 6bbd88c9929e891eb10cbaf3eb4bb785669c71c5 Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Mon, 13 Oct 2025 15:26:55 -0400 Subject: [PATCH 2/6] add check --- .github/workflows/check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 85b823a..446fc48 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -62,6 +62,8 @@ jobs: odin check thread/sync_mutex $FLAGS odin check thread/pool/basic $FLAGS + odin check lua/global_variables $FLAGS + odin check math/noise/draw_texture $FLAGS odin check math/rand/markov $FLAGS From ad242bd5c1ecf1308e02fe5e31681b35f4176876 Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Mon, 13 Oct 2025 17:35:38 -0400 Subject: [PATCH 3/6] cleaned up comment --- lua/global_variables/global_variables.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin index 7a161e4..b98d9eb 100644 --- a/lua/global_variables/global_variables.odin +++ b/lua/global_variables/global_variables.odin @@ -14,7 +14,7 @@ main :: proc() { lua.open_base(state) // Set a new global integer (a Lua 5.3+ feature!) called "answer" to 42 - // First we push the integer to the stack, which is our "postboard" to talk with the Lua VM + // First push the integer to the stack, essentially a "postboard" to talk with the Lua VM lua.pushinteger(state, 42) // Pops the top value on the stack and creates a global with it's value lua.setglobal(state, "Answer") From 4bd04123e6a99c76e5fa6f1e525ce1327344e279 Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Mon, 13 Oct 2025 17:43:47 -0400 Subject: [PATCH 4/6] fixed capitalization --- lua/global_variables/global_variables.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin index b98d9eb..d574b3a 100644 --- a/lua/global_variables/global_variables.odin +++ b/lua/global_variables/global_variables.odin @@ -13,7 +13,7 @@ main :: proc() { // Open the base libraries (print, etc...) lua.open_base(state) - // Set a new global integer (a Lua 5.3+ feature!) called "answer" to 42 + // Set a new global integer (a Lua 5.3+ feature!) called "Answer" to 42 // First push the integer to the stack, essentially a "postboard" to talk with the Lua VM lua.pushinteger(state, 42) // Pops the top value on the stack and creates a global with it's value From 64c34deaf834a413764905dfbc0f1835c582d65c Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Mon, 13 Oct 2025 18:13:26 -0400 Subject: [PATCH 5/6] fix package name --- lua/global_variables/global_variables.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin index d574b3a..eacda8e 100644 --- a/lua/global_variables/global_variables.odin +++ b/lua/global_variables/global_variables.odin @@ -1,4 +1,4 @@ -package main +package global_variables import lua "vendor:lua/5.4" import "core:fmt" From 29f1b8f74e5fd990debdcc0ab2ef591c139dbbd0 Mon Sep 17 00:00:00 2001 From: RobinsAviary Date: Tue, 14 Oct 2025 18:26:08 -0400 Subject: [PATCH 6/6] removed unnecessary parenthesis --- lua/global_variables/global_variables.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin index eacda8e..62b1e9b 100644 --- a/lua/global_variables/global_variables.odin +++ b/lua/global_variables/global_variables.odin @@ -20,7 +20,7 @@ main :: proc() { lua.setglobal(state, "Answer") // Run code and check if it succeeded - if (lua.L_dostring(state, CODE) != 0) { + if lua.L_dostring(state, CODE) != 0 { // Get the error string from the top of the stack and print it error := lua.tostring(state, -1) fmt.println(error)