diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-08-04 22:36:56 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-08-04 22:36:56 +0530 |
| commit | c7e105ee4254d00f591c4c002f32c223f4c2448a (patch) | |
| tree | 17ebadd5dc1a5e148c4b2f5ed1c70b7c7e54fe1a /src/LuaRuntime.cpp | |
| parent | 0d1258aee3f39c8d5348588a87e804ec8cd27bd5 (diff) | |
| download | null-browser-c7e105ee4254d00f591c4c002f32c223f4c2448a.tar.gz null-browser-c7e105ee4254d00f591c4c002f32c223f4c2448a.zip | |
Add on_result callback for web.view.run_js
Diffstat (limited to 'src/LuaRuntime.cpp')
| -rw-r--r-- | src/LuaRuntime.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index 343266c..76dfb11 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -3,6 +3,7 @@ #include <cstdlib> #include <cstring> #include <lua.hpp> +#include <optional> #include <qvariant.h> extern "C" { #include <luv/luv.h> @@ -157,3 +158,39 @@ QVariant LuaRuntime::get_lua_value(lua_State *state, int idx, QVariant default_v return lua_tostring(state, idx); } + +void LuaRuntime::push_qvariant(lua_State *state, std::optional<QVariant> opt) { + if (!opt.has_value()) { + lua_pushnil(state); + return; + } + + auto type = QString(opt.value().typeName()); + // qDebug() << type << opt.value(); + + // TODO: QVariantMap + // TODO: QVariantList + + if (type == "") { + lua_pushnil(state); + return; + } + + if (type == "bool") { + lua_pushboolean(state, opt.value().toBool()); + return; + } + + if (type == "int") { + lua_pushinteger(state, opt.value().toInt()); + return; + } + + if (type == "double") { + lua_pushnumber(state, opt.value().toDouble()); + return; + } + + // String default + lua_pushstring(state, opt.value().toString().toStdString().c_str()); +} |
