console.add_command arguments validation

This commit is contained in:
MihailRis
2024-05-17 02:39:33 +03:00
parent d0b7dec225
commit 8d6f52c1fa
3 changed files with 6 additions and 2 deletions
+4 -1
View File
@@ -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;
}