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 diff --git a/lua/global_variables/global_variables.odin b/lua/global_variables/global_variables.odin new file mode 100644 index 0000000..62b1e9b --- /dev/null +++ b/lua/global_variables/global_variables.odin @@ -0,0 +1,33 @@ +package global_variables + +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 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") + + // 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