From 6b1d49e607da16853d1a0f460dbe756538e4790c Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 9 Mar 2025 22:09:09 +0530 Subject: Add lua integration for command input (web.open, web.tabopen) --- src/LuaRuntime.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/LuaRuntime.cpp (limited to 'src/LuaRuntime.cpp') diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp new file mode 100644 index 0000000..37845d3 --- /dev/null +++ b/src/LuaRuntime.cpp @@ -0,0 +1,34 @@ +#include + +#include "LuaRuntime.hpp" + +LuaRuntime::LuaRuntime() { + state = luaL_newstate(); + luaL_openlibs(state); + + luaL_Reg weblib[] = { + {"open", &LuaRuntime::lua_onUrlOpen}, + {"tabopen", &LuaRuntime::lua_onUrlTabOpen}, + {NULL, NULL}, + }; + luaL_newlib(state, weblib); + lua_setglobal(state, "web"); +} + +void LuaRuntime::evaluate(const char *code) { luaL_dostring(state, code); } + +int LuaRuntime::lua_onUrlOpen(lua_State *state) { + const char *url = luaL_optstring(state, 1, ""); + auto runtime = LuaRuntime::instance(); + emit runtime->urlOpenned(url, OpenType::OpenUrl); + return 1; +} + +int LuaRuntime::lua_onUrlTabOpen(lua_State *state) { + const char *url = luaL_optstring(state, 1, ""); + auto runtime = LuaRuntime::instance(); + emit runtime->urlOpenned(url, OpenType::OpenUrlInTab); + return 1; +} + +LuaRuntime::~LuaRuntime() { lua_close(state); } -- cgit v1.3.1