improve error proofness

This commit is contained in:
Syping 2018-08-23 17:02:12 +02:00
parent 53e8d9abe5
commit 115d384f88

View file

@ -293,7 +293,7 @@ int LuaEngine::luaDeletePointer_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL && ((QObject*)pointer)->inherits("QObject")) {
if (pointer != NULL) {
switch (getVariant(L_p, 2).toInt())
{
case 1:
@ -310,19 +310,22 @@ int LuaEngine::luaDeletePointer_p(lua_State *L_p)
int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 3) {
QObject *object = (QObject*)getPointer(L_p, 1);
QString signalString = getVariant(L_p, 2).toString();
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
if (signalIndex != -1) {
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
if (slotIndex != -1) {
QMetaMethod signal = object->metaObject()->method(signalIndex);
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString());
QObject::connect(object, signal, engine, slot);
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
QObject *object = (QObject*)pointer;
QString signalString = getVariant(L_p, 2).toString();
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
if (signalIndex != -1) {
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
if (slotIndex != -1) {
QMetaMethod signal = object->metaObject()->method(signalIndex);
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString());
QObject::connect(object, signal, engine, slot);
}
}
}
}
@ -332,19 +335,22 @@ int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
int LuaEngine::luaTriggerDisconnect_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
QObject *object = (QObject*)getPointer(L_p, 1);
QString signalString = getVariant(L_p, 2).toString();
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
if (signalIndex != -1) {
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
if (slotIndex != -1) {
QMetaMethod signal = object->metaObject()->method(signalIndex);
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), QVariant());
QObject::disconnect(object, signal, engine, slot);
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
QObject *object = (QObject*)pointer;
QString signalString = getVariant(L_p, 2).toString();
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
if (signalIndex != -1) {
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
if (slotIndex != -1) {
QMetaMethod signal = object->metaObject()->method(signalIndex);
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), QVariant());
QObject::disconnect(object, signal, engine, slot);
}
}
}
}