MCPcopy Index your code
hub / github.com/Shopify/go-lua / Example

Function Example

package_test.go:13–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11}
12
13func Example() {
14 steps := []step{}
15 l := lua.NewState()
16 lua.BaseOpen(l)
17 _ = lua.NewMetaTable(l, "stepMetaTable")
18 lua.SetFunctions(l, []lua.RegistryFunction{{"__newindex", func(l *lua.State) int {
19 k, v := lua.CheckString(l, 2), l.ToValue(3)
20 steps = append(steps, step{name: k, function: v})
21 return 0
22 }}}, 0)
23 l.PushUserData(steps)
24 l.PushValue(-1)
25 l.SetGlobal("step")
26 lua.SetMetaTableNamed(l, "stepMetaTable")
27 lua.LoadString(l, `step.request_tracking_js = function ()
28 get(config.domain..'/javascripts/shopify_stats.js')
29 end`)
30 l.Call(0, 0)
31 fmt.Println(steps[0].name)
32 // Output: request_tracking_js
33}

Callers

nothing calls this directly

Calls 5

ToValueMethod · 0.95
PushUserDataMethod · 0.95
PushValueMethod · 0.95
SetGlobalMethod · 0.95
CallMethod · 0.95

Tested by

no test coverage detected