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
2 changes: 2 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions lua/global_variables/global_variables.odin
Original file line number Diff line number Diff line change
@@ -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)
}