refactor lua libraries

This commit is contained in:
MihailRis
2024-07-22 18:14:54 +03:00
parent cfe1f1ad28
commit b5e7b63a9d
3 changed files with 42 additions and 53 deletions
+24
View File
@@ -3,6 +3,7 @@
#include "lua_util.hpp"
#include <string>
#include <exception>
/// Definitions can be found in local .cpp files
@@ -45,6 +46,29 @@ extern const luaL_Reg transformlib [];
// Lua Overrides
extern int l_print(lua::State* L);
namespace lua {
inline uint check_argc(lua::State* L, int a) {
int argc = lua::gettop(L);
if (argc == a) {
return static_cast<uint>(argc);
} else {
throw std::runtime_error(
"invalid number of arguments (" + std::to_string(a) +
" expected)");
}
}
inline uint check_argc(lua::State* L, int a, int b) {
int argc = lua::gettop(L);
if (argc == a || argc == b) {
return static_cast<uint>(argc);
} else {
throw std::runtime_error(
"invalid number of arguments (" + std::to_string(a) + " or " +
std::to_string(b) + " expected)");
}
}
}
void initialize_libs_extends(lua::State* L);
#endif // LOGIC_SCRIPTING_API_LUA_HPP_