console.add_command arguments validation
This commit is contained in:
parent
d0b7dec225
commit
8d6f52c1fa
@ -356,7 +356,7 @@ dynamic::Value lua::LuaState::tovalue(int idx) {
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
"lua type "+std::to_string(type)+" is not supported"
|
||||
"lua type "+std::string(luaL_typename(L, type))+" is not supported"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,9 @@ namespace scripting {
|
||||
using namespace scripting;
|
||||
|
||||
static int l_add_command(lua_State* L) {
|
||||
if (!lua_isstring(L, 1) || !lua_isstring(L, 2) || !lua_isfunction(L, 3)) {
|
||||
throw std::runtime_error("invalid argument type");
|
||||
}
|
||||
auto scheme = lua_tostring(L, 1);
|
||||
auto description = lua_tostring(L, 2);
|
||||
lua_pushvalue(L, 3);
|
||||
@ -25,7 +28,7 @@ static int l_add_command(lua_State* L) {
|
||||
}
|
||||
);
|
||||
} catch (const parsing_error& err) {
|
||||
luaL_error(L, ("command scheme error:\n"+err.errorLog()).c_str());
|
||||
throw std::runtime_error(("command scheme error:\n"+err.errorLog()).c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#else
|
||||
#include <lua.hpp>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
namespace lua {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user