This example receives a variable number of numerical arguments and returns their average and sum.
(l *lua.State)
| 6 | |
| 7 | // This example receives a variable number of numerical arguments and returns their average and sum. |
| 8 | func ExampleFunction(l *lua.State) int { |
| 9 | n := l.Top() // Number of arguments. |
| 10 | var sum float64 |
| 11 | for i := 1; i <= n; i++ { |
| 12 | f, ok := l.ToNumber(i) |
| 13 | if !ok { |
| 14 | l.PushString("incorrect argument") |
| 15 | l.Error() |
| 16 | } |
| 17 | sum += f |
| 18 | } |
| 19 | l.PushNumber(sum / float64(n)) // First result. |
| 20 | l.PushNumber(sum) // Second result. |
| 21 | return 2 // Result count. |
| 22 | } |
nothing calls this directly
no test coverage detected