diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-09 22:09:09 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-09 23:41:36 +0530 |
| commit | 6b1d49e607da16853d1a0f460dbe756538e4790c (patch) | |
| tree | d5c784e6e568272afbb7530ea5dd752ce835b8fa /src/LuaRuntime.cpp | |
| parent | 61f99089288138989cf244d174882aa5088b738b (diff) | |
| download | null-browser-6b1d49e607da16853d1a0f460dbe756538e4790c.tar.gz null-browser-6b1d49e607da16853d1a0f460dbe756538e4790c.zip | |
Add lua integration for command input (web.open, web.tabopen)
Diffstat (limited to 'src/LuaRuntime.cpp')
| -rw-r--r-- | src/LuaRuntime.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 <lua.hpp> + +#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); } |
