| 14 | } |
| 15 | |
| 16 | inline std::int64_t getInteger(const sol::stack_proxy arg, const size_t n, std::string_view name) |
| 17 | { |
| 18 | double integer; |
| 19 | if (!arg.is<double>()) |
| 20 | throw std::runtime_error(std::format("bad argument #{} to '{}' (number expected, got {})", n, name, |
| 21 | sol::type_name(arg.lua_state(), arg.get_type()))); |
| 22 | |
| 23 | if (std::modf(arg, &integer) != 0) |
| 24 | throw std::runtime_error( |
| 25 | std::format("bad argument #{} to '{}' (number has no integer representation)", n, name)); |
| 26 | |
| 27 | return static_cast<std::int64_t>(integer); |
| 28 | } |
| 29 | |
| 30 | // If the input 'pos' is negative, it is treated as counting from the end of the string, |
| 31 | // where -1 represents the last character position, -2 represents the second-to-last position, |
no test coverage detected