-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
33 lines (28 loc) · 833 Bytes
/
main.go
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
28
29
30
31
32
33
package main
import (
"os"
"github.com/arnodel/golua/examples/userdata/regexlib"
"github.com/arnodel/golua/lib"
"github.com/arnodel/golua/lib/base"
"github.com/arnodel/golua/lib/packagelib"
rt "github.com/arnodel/golua/runtime"
)
const code = `
regex = require("regex")
ptn = regex.new("[0-9]+")
print("ptn:", ptn)
match = ptn:find("hello there 123 yippee")
print("found:", match)
`
func main() {
r := rt.New(os.Stdout) // Create runtime
lib.LoadLibs(
r,
base.LibLoader, // Load base lib (needed for print)
packagelib.LibLoader, // Load package lib (needed for require)
regexlib.LibLoader, // Load our example lib
)
// Now compile and run the lua code
chunk, _ := r.CompileAndLoadLuaChunk("test", []byte(code), rt.TableValue(r.GlobalEnv()))
_, _ = rt.Call1(r.MainThread(), rt.FunctionValue(chunk))
}