Call calls a function. To do so, use the following protocol: first, the function to be called is pushed onto the stack; then, the arguments to the function are pushed in direct order - that is, the first argument is pushed first. Finally, call Call. argCount is the number of arguments that you pushed onto the stack. All arguments and the function value are popped from the stack when the function is called.
The results are pushed onto the stack when the function returns. The number of results is adjusted to resultCount, unless resultCount is MultipleReturns. In this case, all results from the function are pushed. Lua takes care that the returned values fit into the stack space. The function results are pushed onto the stack in direct order (the first result is pushed first), so that after the call the last result is on the top of the stack.
Any error inside the called function provokes a call to panic().
The following example shows how the host program can do the equivalent to this Lua code:
a = f("how", t.x, 14)
Here it is in Go:
l.Global("f") // Function to be called. l.PushString("how") // 1st argument. l.Global("t") // Table to be indexed. l.Field(-1, "x") // Push result of t.x (2nd arg). l.Remove(-2) // Remove t from the stack. l.PushInteger(14) // 3rd argument. l.Call(3, 1) // Call f with 3 arguments and 1 result. l.SetGlobal("a") // Set global a.
Note that the code above is "balanced": at its end, the stack is back to its original configuration. This is considered good programming practice.
} l.PushValue(index) l.Call(1, 1) return true }
l.PushGoFunction(f) l.PushString(name) // argument to f l.Call(1, 1) // open module SubTable(l, RegistryIndex, "_LOADED") l.PushValue(-2) // make copy of module (call result)
Call is referenced in 3 repositoriesgithub.com/Shopify/go-lua
- 3 references in base.go
- 2 references in auxiliary.go
- 2 references in load.go
- 2 references in parser_test.go
- 2 references in vm_test.go
- 2 references in util/deep_pull_test.go
- 1 reference in go-lua/example/main.go