Skip to content

Commit cce1a63

Browse files
authored
added hello world lua example (odin-lang#146)
1 parent 2e75eb7 commit cce1a63

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
odin check thread/pool/basic $FLAGS
6464
6565
odin check lua/global_variables $FLAGS
66+
odin check lua/hellope_lua $FLAGS
6667
6768
odin check math/noise/draw_texture $FLAGS
6869
odin check math/rand/markov $FLAGS

lua/hellope_lua/hellope_lua.odin

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package hellope_lua
2+
3+
import lua "vendor:lua/5.4"
4+
import "core:fmt"
5+
6+
// The code the Lua VM will run
7+
CODE :: "print(\"Hellope, Lua!\")"
8+
9+
main :: proc() {
10+
// Create new Lua state
11+
state := lua.L_newstate()
12+
13+
// Open the base libraries (print, etc...)
14+
lua.open_base(state)
15+
16+
// Run code and check if it succeeded
17+
if lua.L_dostring(state, CODE) != 0 {
18+
// Get the error string from the top of the stack and print it
19+
error := lua.tostring(state, -1)
20+
fmt.println(error)
21+
// Pop the error off of the stack
22+
lua.pop(state, 1)
23+
}
24+
25+
// Closes the Lua VM, deallocating all memory
26+
lua.close(state)
27+
}

0 commit comments

Comments
 (0)