| 4 | #include <iostream> |
| 5 | |
| 6 | sol::variadic_results call_it(sol::object function_name, |
| 7 | sol::variadic_args args, sol::this_environment env, |
| 8 | sol::this_state L) { |
| 9 | sol::state_view lua = L; |
| 10 | // default to global table as environment |
| 11 | sol::environment function_environment = lua.globals(); |
| 12 | if (env) { |
| 13 | // if we have an environment, use that instead |
| 14 | function_environment = env; |
| 15 | } |
| 16 | |
| 17 | // get and call the function |
| 18 | sol::protected_function pf |
| 19 | = function_environment[function_name]; |
| 20 | sol::protected_function_result res = pf(args); |
| 21 | |
| 22 | // |
| 23 | sol::variadic_results results; |
| 24 | if (!res.valid()) { |
| 25 | // something went wrong: log/crash/whatever |
| 26 | return results; |
| 27 | } |
| 28 | int returncount = res.return_count(); |
| 29 | for (int i = 0; i < returncount; i++) { |
| 30 | // pass offset to get the object that was returned |
| 31 | sol::object obj = res.get<sol::object>(i); |
| 32 | results.push_back(obj); |
| 33 | } |
| 34 | // return the results |
| 35 | return results; |
| 36 | } |
| 37 | |
| 38 | int main(int, char*[]) { |
| 39 | std::cout << "=== indirect function calls ===" << std::endl; |
nothing calls this directly
no test coverage detected