refactor lua libraries
This commit is contained in:
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user