Files
golua/_example/basic.go
T
2021-09-21 22:30:03 +03:00

51 lines
810 B
Go

package main
import (
"fmt"
"github.com/vxcontrol/golua/lua"
)
func test(L *lua.State) int {
fmt.Println("hello world! from go!")
return 0
}
func test2(L *lua.State) int {
arg := L.CheckInteger(-1)
argfrombottom := L.CheckInteger(1)
fmt.Print("test2 arg: ")
fmt.Println(arg)
fmt.Print("from bottom: ")
fmt.Println(argfrombottom)
return 0
}
func main() {
L := lua.NewState()
defer L.Close()
L.OpenLibs()
L.GetGlobal("print")
L.PushString("Hello World!")
L.Call(1, 0)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test2)
L.PushInteger(42)
L.Call(1, 0)
L.Call(0, 0)
L.Call(0, 0)
L.Call(0, 0)
// this will fail as we didn't register test2 function
err := L.DoString("test2(42)")
fmt.Printf("Ciao %v\n", err)
}