Created
October 5, 2019 15:35
-
-
Save keenan-v1/2189d7cedd5cde4295f616661b32bc33 to your computer and use it in GitHub Desktop.
Learning lua in an odd way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Hello World") | |
go_print("Hello from Go inside Lua") | |
print(test_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/Shopify/go-lua" | |
) | |
func goPrint(l *lua.State) int { | |
n := l.Top() | |
if n != 1{ | |
panic("expected 1 argument") | |
} | |
s := lua.CheckString(l, 1) | |
fmt.Println(s) | |
return 0 | |
} | |
func main() { | |
l := lua.NewState() | |
lua.OpenLibraries(l) | |
l.PushGoFunction(goPrint) | |
l.SetGlobal("go_print") | |
l.PushString("testing123") | |
l.SetGlobal("test_str") | |
if err := lua.DoFile(l, "hello.lua"); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment