xmppbot 0.6
This commit is contained in:
parent
b95369f254
commit
b7992849fd
4 changed files with 31 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
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)
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setApplicationName(QLatin1String("xmppbot"));
|
||||
app.setApplicationVersion(QLatin1String("0.5"));
|
||||
app.setApplicationVersion(QLatin1String("0.6"));
|
||||
|
||||
QCommandLineParser commandLineParser;
|
||||
commandLineParser.addPositionalArgument(QLatin1String("config"), QCoreApplication::translate("xmppbot", "Configuration file."));
|
||||
|
|
|
@ -61,6 +61,9 @@ XmppBotLua::XmppBotLua(QObject *parent) : QObject(parent)
|
|||
|
||||
// Process
|
||||
pushFunction("executeProcess", executeProcess);
|
||||
|
||||
// Table
|
||||
pushFunction("tableContains", tableContains);
|
||||
}
|
||||
|
||||
XmppBotLua::~XmppBotLua()
|
||||
|
@ -199,7 +202,7 @@ void XmppBotLua::pushVariant(lua_State *L_p, const QVariant &variant)
|
|||
currentId++;
|
||||
}
|
||||
}
|
||||
else if ((QMetaType::Type)variant.type() == QMetaType::QVariantList) {
|
||||
else if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QVariantList) {
|
||||
const QVariantList variantList = variant.toList();
|
||||
lua_createtable(L_p, 0, variantList.count());
|
||||
int currentId = 1;
|
||||
|
@ -210,7 +213,7 @@ void XmppBotLua::pushVariant(lua_State *L_p, const QVariant &variant)
|
|||
currentId++;
|
||||
}
|
||||
}
|
||||
else if ((QMetaType::Type)variant.type() == QMetaType::QVariantMap) {
|
||||
else if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QVariantMap) {
|
||||
const QVariantMap variantMap = variant.toMap();
|
||||
lua_createtable(L_p, 0, variantMap.count());
|
||||
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);
|
||||
}
|
||||
}
|
||||
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*>());
|
||||
}
|
||||
else {
|
||||
|
@ -489,3 +492,23 @@ int XmppBotLua::executeProcess(lua_State *L_p)
|
|||
pushVariant(L_p, -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;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ private:
|
|||
// Process
|
||||
static int executeProcess(lua_State *L_p);
|
||||
|
||||
// Table
|
||||
static int tableContains(lua_State *L_p);
|
||||
|
||||
// Lua
|
||||
lua_State *L;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue