diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-04-14 00:44:15 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-04-14 00:44:15 +0530 |
| commit | 6869ca66e15259996c45501f1a40a0b354262815 (patch) | |
| tree | 13fc287f86f75c537e5b743918354a4d5b9b9699 /src/LuaRuntime.hpp | |
| parent | 9fc1e934cd2c58ed1ba03f860b09e7a8cd48e792 (diff) | |
| download | null-browser-6869ca66e15259996c45501f1a40a0b354262815.tar.gz null-browser-6869ca66e15259996c45501f1a40a0b354262815.zip | |
Refactor lua runtime api
Diffstat (limited to 'src/LuaRuntime.hpp')
| -rw-r--r-- | src/LuaRuntime.hpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp index 4978c74..f684409 100644 --- a/src/LuaRuntime.hpp +++ b/src/LuaRuntime.hpp @@ -39,7 +39,6 @@ public: void start_event_loop(); DELEGATE(event_loop, queue_task, queue_task) - QVariant get_lua_value(int idx, QVariant default_value = 0); DEFINE_GETTER(get_state, state) signals: @@ -57,21 +56,8 @@ signals: protected: LuaRuntime(); ~LuaRuntime() override; - void init_web_lib(); - - // Lua api - static int lua_history_back(lua_State *state); - static int lua_history_forward(lua_State *state); - static int lua_event_register(lua_State *state); - static int lua_keymap_set(lua_State *state); - static int lua_open_url(lua_State *state); - static int lua_view_close(lua_State *state); - static int lua_view_create(lua_State *state); - static int lua_view_current(lua_State *state); - static int lua_view_list(lua_State *state); - static int lua_view_select(lua_State *state); - static int lua_config_set(lua_State *state); - static int lua_config_get(lua_State *state); + void init_lua_package_path(); + void init_web_api(); private: lua_State *state; @@ -107,4 +93,20 @@ public: return values; } + + static QVariant get_lua_value(lua_State *state, int idx, QVariant default_value = 0) { + if (lua_isnoneornil(state, idx)) + return default_value; + + if (lua_isstring(state, idx)) + return lua_tostring(state, idx); + + if (lua_isboolean(state, idx)) + return lua_toboolean(state, idx); + + if (lua_isnumber(state, idx)) + return lua_tonumber(state, idx); + + return lua_tostring(state, idx); + } }; |
