xmppbot 0.6

This commit is contained in:
Syping 2021-08-06 05:33:01 +02:00
parent b95369f254
commit b7992849fd
4 changed files with 31 additions and 5 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.7)
project(xmppbot VERSION 0.5 LANGUAGES CXX) project(xmppbot VERSION 0.6 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)

View file

@ -39,7 +39,7 @@ int main(int argc, char *argv[])
{ {
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
app.setApplicationName(QLatin1String("xmppbot")); app.setApplicationName(QLatin1String("xmppbot"));
app.setApplicationVersion(QLatin1String("0.5")); app.setApplicationVersion(QLatin1String("0.6"));
QCommandLineParser commandLineParser; QCommandLineParser commandLineParser;
commandLineParser.addPositionalArgument(QLatin1String("config"), QCoreApplication::translate("xmppbot", "Configuration file.")); commandLineParser.addPositionalArgument(QLatin1String("config"), QCoreApplication::translate("xmppbot", "Configuration file."));

View file

@ -61,6 +61,9 @@ XmppBotLua::XmppBotLua(QObject *parent) : QObject(parent)
// Process // Process
pushFunction("executeProcess", executeProcess); pushFunction("executeProcess", executeProcess);
// Table
pushFunction("tableContains", tableContains);
} }
XmppBotLua::~XmppBotLua() XmppBotLua::~XmppBotLua()
@ -199,7 +202,7 @@ void XmppBotLua::pushVariant(lua_State *L_p, const QVariant &variant)
currentId++; currentId++;
} }
} }
else if ((QMetaType::Type)variant.type() == QMetaType::QVariantList) { else if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QVariantList) {
const QVariantList variantList = variant.toList(); const QVariantList variantList = variant.toList();
lua_createtable(L_p, 0, variantList.count()); lua_createtable(L_p, 0, variantList.count());
int currentId = 1; int currentId = 1;
@ -210,7 +213,7 @@ void XmppBotLua::pushVariant(lua_State *L_p, const QVariant &variant)
currentId++; currentId++;
} }
} }
else if ((QMetaType::Type)variant.type() == QMetaType::QVariantMap) { else if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QVariantMap) {
const QVariantMap variantMap = variant.toMap(); const QVariantMap variantMap = variant.toMap();
lua_createtable(L_p, 0, variantMap.count()); lua_createtable(L_p, 0, variantMap.count());
for (auto it = variantMap.constBegin(); it != variantMap.constEnd(); it++) { for (auto it = variantMap.constBegin(); it != variantMap.constEnd(); it++) {
@ -219,7 +222,7 @@ void XmppBotLua::pushVariant(lua_State *L_p, const QVariant &variant)
lua_settable(L_p, -3); lua_settable(L_p, -3);
} }
} }
else if ((QMetaType::Type)variant.type() == QMetaType::Void || (QMetaType::Type)variant.type() == QMetaType::VoidStar) { else if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::Void || static_cast<QMetaType::Type>(variant.type()) == QMetaType::VoidStar) {
lua_pushlightuserdata(L_p, variant.value<void*>()); lua_pushlightuserdata(L_p, variant.value<void*>());
} }
else { else {
@ -489,3 +492,23 @@ int XmppBotLua::executeProcess(lua_State *L_p)
pushVariant(L_p, -2); pushVariant(L_p, -2);
return 2; return 2;
} }
int XmppBotLua::tableContains(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
const QVariant vtable = getVariant(L_p, 1);
if (static_cast<QMetaType::Type>(vtable.type()) == QMetaType::QVariantMap) {
const QVariantMap table = vtable.toMap();
const QVariant toMatch = getVariant(L_p, 2);
for (const QVariant &value : table) {
if (value == toMatch) {
pushVariant(L_p, true);
return 1;
}
}
pushVariant(L_p, false);
return 1;
}
}
return 0;
}

View file

@ -83,6 +83,9 @@ private:
// Process // Process
static int executeProcess(lua_State *L_p); static int executeProcess(lua_State *L_p);
// Table
static int tableContains(lua_State *L_p);
// Lua // Lua
lua_State *L; lua_State *L;
}; };