diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-27 14:54:56 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-27 14:54:56 +0530 |
| commit | 9ece6a733f0c3bfd518ee14f520aed70124fac12 (patch) | |
| tree | 54d045b187d39bf05c6f2653adb78bf2088f45ce /src/LuaRuntime.cpp | |
| parent | f13a1a1c4eab8bdef3760dd71cd7e2b3cc68a3e8 (diff) | |
| download | null-browser-9ece6a733f0c3bfd518ee14f520aed70124fac12.tar.gz null-browser-9ece6a733f0c3bfd518ee14f520aed70124fac12.zip | |
Add more tests for api + webview + webviewstack
Diffstat (limited to '')
| -rw-r--r-- | src/LuaRuntime.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index e9dc86f..343266c 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -112,3 +112,48 @@ LuaRuntime::~LuaRuntime() { lua_close(state); state = nullptr; } + +std::vector<QString> LuaRuntime::lua_tostringlist(lua_State *state) { + std::vector<QString> values; + if (!lua_istable(state, -1)) + return values; + + lua_pushnil(state); // First key for lua_next() + while (lua_next(state, -2) != 0) { + if (lua_isstring(state, -1)) + values.emplace_back(lua_tostring(state, -1)); + lua_pop(state, 1); + } + lua_pop(state, 1); + + return values; +} + +void LuaRuntime::inspect_lua_stack(lua_State *state) { + int top = lua_gettop(state); + qDebug() << "--- Lua Stack (top: " << top << ") ---\n"; + + for (int i = 1; i <= top; i++) { + int type = lua_type(state, i); + qDebug() << " " << i << ": " << lua_typename(state, type); + } + + qDebug() << "---------------------------\n"; + lua_settop(state, top); +} + +QVariant LuaRuntime::get_lua_value(lua_State *state, int idx, QVariant default_value) { + 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); +} |
