fix: lua coroutines support

This commit is contained in:
MihailRis
2024-06-11 01:52:28 +03:00
parent 590f9757c0
commit 7973a9c32b
15 changed files with 707 additions and 740 deletions
+6 -7
View File
@@ -16,29 +16,28 @@ namespace scripting {
extern lua::LuaState* state;
extern Hud* hud;
}
using namespace scripting;
static int l_keycode(lua_State* L) {
const char* name = state->requireString(1);
auto name = lua::require_string(L, 1);
lua_pushinteger(L, static_cast<int>(input_util::keycode_from(name)));
return 1;
}
static int l_mousecode(lua_State* L) {
const char* name = state->requireString(1);
auto name = lua::require_string(L, 1);
lua_pushinteger(L, static_cast<int>(input_util::mousecode_from(name)));
return 1;
}
static int l_add_callback(lua_State*) {
auto bindname = state->requireString(1);
static int l_add_callback(lua_State* L) {
auto bindname = lua::require_string(L, 1);
const auto& bind = Events::bindings.find(bindname);
if (bind == Events::bindings.end()) {
throw std::runtime_error("unknown binding "+util::quote(bindname));
}
state->pushvalue(2);
runnable actual_callback = state->createRunnable();
lua_pushvalue(L, 2);
runnable actual_callback = state->createRunnable(L);
runnable callback = [=]() {
if (!scripting::engine->getGUI()->isFocusCaught()) {
actual_callback();