-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
27 lines (22 loc) · 609 Bytes
/
Copy pathmain.go
File metadata and controls
27 lines (22 loc) · 609 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// basic is the README quickstart as a runnable program: embed the VM, expose a
// Go function, run a script, and read the results back.
package main
import (
"fmt"
luapure "github.com/htcom-code/lua-pure/lua"
)
func main() {
L := luapure.NewState()
L.OpenLibs()
// Expose a Go function to Lua.
L.Register("greet", func(L *luapure.LState) int {
who := L.CheckString(1)
L.Push(luapure.MkString("hello, " + who))
return 1
})
res, err := L.DoString(`return greet("world"), 6 * 7`, "=quickstart")
if err != nil {
panic(err)
}
fmt.Println(res[0].Str(), res[1].AsInt()) // hello, world 42
}