forked from Shopify/go-lua
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage_test.go
More file actions
33 lines (30 loc) · 748 Bytes
/
package_test.go
File metadata and controls
33 lines (30 loc) · 748 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
28
29
30
31
32
33
package lua_test
import (
"fmt"
"github.com/Shopify/go-lua"
)
type step struct {
name string
function interface{}
}
func Example() {
steps := []step{}
l := lua.NewState()
lua.BaseOpen(l)
_ = lua.NewMetaTable(l, "stepMetaTable")
lua.SetFunctions(l, []lua.RegistryFunction{{"__newindex", func(l *lua.State) int {
k, v := lua.CheckString(l, 2), l.ToValue(3)
steps = append(steps, step{name: k, function: v})
return 0
}}}, 0)
l.PushUserData(steps)
l.PushValue(-1)
l.SetGlobal("step")
lua.SetMetaTableNamed(l, "stepMetaTable")
lua.LoadString(l, `step.request_tracking_js = function ()
get(config.domain..'/javascripts/shopify_stats.js')
end`)
l.Call(0, 0)
fmt.Println(steps[0].name)
// Output: request_tracking_js
}