mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-04 21:16:56 +01:00
improve error proofness
This commit is contained in:
parent
53e8d9abe5
commit
115d384f88
1 changed files with 33 additions and 27 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue