diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-26 00:56:14 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-26 00:56:14 +0530 |
| commit | 68448538172663279919b29dd09b5faa51e0628a (patch) | |
| tree | 032a321c645fca3aec7ba52efd60b55048536b2b /src/LuaRuntimeApi.hpp | |
| parent | 3f56d76a2b0d528c05ab8d0a38059ca82ba90952 (diff) | |
| download | null-browser-68448538172663279919b29dd09b5faa51e0628a.tar.gz null-browser-68448538172663279919b29dd09b5faa51e0628a.zip | |
Add web.schedule to schedule an action after qt+libuv tick
Diffstat (limited to 'src/LuaRuntimeApi.hpp')
| -rw-r--r-- | src/LuaRuntimeApi.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp index 17e0fe9..06323f0 100644 --- a/src/LuaRuntimeApi.hpp +++ b/src/LuaRuntimeApi.hpp @@ -10,6 +10,27 @@ #include "widgets/BrowserWindow.hpp" #include "widgets/Decorations.hpp" +int lua_api_schedule_fn(lua_State *state) { + lua_pushvalue(state, 1); + const int function_ref = luaL_ref(state, LUA_REGISTRYINDEX); + auto action = [state, function_ref]() { + preserve_top(state, { + lua_rawgeti(state, LUA_REGISTRYINDEX, function_ref); + if (lua_pcall(state, 0, 0, 0) != LUA_OK) { + const char *error = lua_tostring(state, -1); + qDebug() << "Error calling Lua function:" << error; + } + luaL_unref(state, LUA_REGISTRYINDEX, function_ref); + }) + }; + + auto &runtime = LuaRuntime::instance(); + emit runtime.schedule_for_next_tick(action); + + lua_pushnil(state); + return 1; +} + int lua_api_view_set_url(lua_State *state) { const char *url = lua_tostring(state, 1); WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); @@ -78,6 +99,7 @@ int lua_api_keymap_set(lua_State *state) { auto &runtime = LuaRuntime::instance(); emit runtime.keymap_add_requested(mode, keyseq, action); + lua_pushnil(state); return 1; } @@ -337,5 +359,6 @@ static luaL_Reg internals_api[] = { luaL_Reg{"decorations_set_enabled", &lua_api_decorations_set_enabled}, luaL_Reg{"decorations_get_enabled", &lua_api_decorations_get_enabled}, luaL_Reg{"decorations_get_view", &lua_api_decorations_get_view}, + luaL_Reg{"schedule", &lua_api_schedule_fn}, luaL_Reg{nullptr, nullptr}, }; |
