aboutsummaryrefslogtreecommitdiff
path: root/src/LuaRuntime.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-25 20:26:40 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-25 20:26:40 +0530
commit1284f8cf39e8ba44e837d4dac0bace89cb7a0c26 (patch)
tree58ff313869ca62b335a8412289e3bbec1c104f47 /src/LuaRuntime.cpp
parent4cbaaae7c55e71d2d4db591029394812077eb844 (diff)
downloadnull-browser-1284f8cf39e8ba44e837d4dac0bace89cb7a0c26.tar.gz
null-browser-1284f8cf39e8ba44e837d4dac0bace89cb7a0c26.zip
Refactor webview index with id + add web.tabs.close
Diffstat (limited to '')
-rw-r--r--src/LuaRuntime.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index 0149e10..1fb722a 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -107,7 +107,7 @@ int LuaRuntime::lua_add_keymap(lua_State *state) {
// TODO: Cleanup function ref on after keymap clear
auto *runtime = LuaRuntime::instance();
- emit runtime->keymap_add_requested(mode, keyseq, action);
+ emit runtime->keymap_added(mode, keyseq, action);
return 1;
}
@@ -127,36 +127,41 @@ void LuaRuntime::init_web_lib() {
// NOLINTBEGIN(modernize-avoid-c-arrays)
// web
- luaL_Reg weblib[] = {
+ luaL_Reg web[] = {
{"open", &LuaRuntime::lua_on_url_open},
- {"tabopen", &LuaRuntime::lua_on_url_tab_open},
{nullptr, nullptr},
};
- luaL_newlib(state, weblib); // NOLINT(readability-math-missing-parentheses)
+ luaL_newlib(state, web);
lua_setglobal(state, web_global_name);
-
- // web.keymap
lua_getglobal(state, web_global_name);
- luaL_Reg keymaplib[] = {
+
+ // Keymap api (web.keymap)
+ luaL_Reg webkeymap[] = {
{"set", &LuaRuntime::lua_add_keymap},
+ {nullptr, nullptr},
};
- luaL_newlib(state, keymaplib); // NOLINT(readability-math-missing-parentheses)
+ luaL_newlib(state, webkeymap);
lua_setfield(state, -2, "keymap");
- // lua_pop(state, 1);
- luaL_Reg tabslib[] = {
+ // Tab actions (web.tabs)
+ luaL_Reg webtabs[] = {
+ {"close", &LuaRuntime::lua_tab_closed},
+ {"new", &LuaRuntime::lua_on_url_tab_open},
{"current", &LuaRuntime::lua_get_current_tab_id},
+ {nullptr, nullptr},
};
- luaL_newlib(state, tabslib); // NOLINT(readability-math-missing-parentheses)
+ luaL_newlib(state, webtabs);
lua_setfield(state, -2, "tabs");
- luaL_Reg historylib[] = {
+ // History navigation
+ luaL_Reg webhistory[] = {
{"back", &LuaRuntime::lua_history_back},
{"forward", &LuaRuntime::lua_history_forward},
+ {nullptr, nullptr},
};
- luaL_newlib(state, // NOLINT(readability-math-missing-parentheses)
- historylib);
+ luaL_newlib(state, webhistory);
lua_setfield(state, -2, "history");
+
// NOLINTEND(modernize-avoid-c-arrays)
}
@@ -201,6 +206,20 @@ int LuaRuntime::lua_history_forward(lua_State *state) {
return 1;
}
+int LuaRuntime::lua_tab_closed(lua_State *state) {
+ auto *runtime = LuaRuntime::instance();
+
+ qsizetype tab_id;
+ if (lua_isnoneornil(state, 2)) {
+ tab_id = runtime->fetch_current_tab_id();
+ } else {
+ tab_id = lua_tointeger(state, 2);
+ }
+
+ emit runtime->webview_closed(tab_id);
+ return 1;
+}
+
LuaRuntime::~LuaRuntime() {
stop_event_loop();
lua_close(state);