add get_binding_text() for script api

This commit is contained in:
Sergwest585 2024-10-20 01:22:49 +03:00
parent 9628068faf
commit 67f7006ad0
3 changed files with 27 additions and 0 deletions

View File

@ -60,6 +60,12 @@ input.get_bindings() -> strings array
Returns all binding names.
```python
input.get_binding_text(bindname: str) -> str
```
Returns text representation of button by binding name.
```python
input.is_pressed(code: str) -> bool
```

View File

@ -58,6 +58,12 @@ input.get_bindings() -> массив строк
Возвращает названия всех доступных привязок.
```python
input.get_binding_text(bindname: str) -> str
```
Возвращает текстовое представление кнопки по имени привязки.
```python
input.is_active(bindname: str) -> bool
```

View File

@ -64,6 +64,20 @@ static int l_get_bindings(lua::State* L) {
return 1;
}
static int l_get_binding_text(lua::State* L) {
auto bindname = lua::require_string(L, 1);
auto index = Events::bindings.find(bindname);
if (index == Events::bindings.end()) {
throw std::runtime_error("unknown binding " + util::quote(bindname));
lua::pushstring(L, "");
} else {
lua::pushstring(L, index->second.text());
}
return 1;
}
static int l_is_active(lua::State* L) {
auto bindname = lua::require_string(L, 1);
const auto& bind = Events::bindings.find(bindname);
@ -101,6 +115,7 @@ const luaL_Reg inputlib[] = {
{"add_callback", lua::wrap<l_add_callback>},
{"get_mouse_pos", lua::wrap<l_get_mouse_pos>},
{"get_bindings", lua::wrap<l_get_bindings>},
{"get_binding_text", lua::wrap<l_get_binding_text>},
{"is_active", lua::wrap<l_is_active>},
{"is_pressed", lua::wrap<l_is_pressed>},
{NULL, NULL}};