From c7e105ee4254d00f591c4c002f32c223f4c2448a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 4 Aug 2025 22:36:56 +0530 Subject: Add on_result callback for web.view.run_js --- src/LuaRuntime.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/LuaRuntime.cpp') 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 #include #include +#include #include extern "C" { #include @@ -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 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()); +} -- cgit v1.3.1