file.find fix + input.mousecode

This commit is contained in:
MihailRis 2024-06-03 17:44:57 +03:00
parent fdd9ede9d5
commit eca050123d
2 changed files with 13 additions and 2 deletions

View File

@ -17,8 +17,12 @@ static fs::path resolve_path(lua_State*, const std::string& path) {
static int l_file_find(lua_State* L) {
std::string path = lua_tostring(L, 1);
lua_pushstring(L, scripting::engine->getResPaths()->findRaw(path).c_str());
return 1;
try {
lua_pushstring(L, scripting::engine->getResPaths()->findRaw(path).c_str());
return 1;
} catch (const std::runtime_error& err) {
return 0;
}
}
static int l_file_resolve(lua_State* L) {

View File

@ -25,6 +25,12 @@ static int l_keycode(lua_State* L) {
return 1;
}
static int l_mousecode(lua_State* L) {
const char* name = state->requireString(1);
lua_pushinteger(L, static_cast<int>(input_util::mousecode_from(name)));
return 1;
}
static int l_add_callback(lua_State* L) {
auto bindname = state->requireString(1);
const auto& bind = Events::bindings.find(bindname);
@ -51,6 +57,7 @@ static int l_get_mouse_pos(lua_State* L) {
const luaL_Reg inputlib [] = {
{"keycode", lua_wrap_errors<l_keycode>},
{"mousecode", lua_wrap_errors<l_mousecode>},
{"add_callback", lua_wrap_errors<l_add_callback>},
{"get_mouse_pos", lua_wrap_errors<l_get_mouse_pos>},
{NULL, NULL}