mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 20:05:30 +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) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
void *pointer = getPointer(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())
|
switch (getVariant(L_p, 2).toInt())
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -310,19 +310,22 @@ int LuaEngine::luaDeletePointer_p(lua_State *L_p)
|
||||||
int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
|
int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 3) {
|
if (getArgumentCount(L_p) >= 3) {
|
||||||
QObject *object = (QObject*)getPointer(L_p, 1);
|
void *pointer = getPointer(L_p, 1);
|
||||||
QString signalString = getVariant(L_p, 2).toString();
|
if (pointer != NULL) {
|
||||||
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
|
QObject *object = (QObject*)pointer;
|
||||||
if (signalIndex != -1) {
|
QString signalString = getVariant(L_p, 2).toString();
|
||||||
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
|
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
|
||||||
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
|
if (signalIndex != -1) {
|
||||||
if (slotIndex != -1) {
|
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
|
||||||
QMetaMethod signal = object->metaObject()->method(signalIndex);
|
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
|
||||||
QMetaMethod slot = engine->metaObject()->method(slotIndex);
|
if (slotIndex != -1) {
|
||||||
QString funcStorage;
|
QMetaMethod signal = object->metaObject()->method(signalIndex);
|
||||||
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
|
QMetaMethod slot = engine->metaObject()->method(slotIndex);
|
||||||
pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString());
|
QString funcStorage;
|
||||||
QObject::connect(object, signal, engine, slot);
|
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)
|
int LuaEngine::luaTriggerDisconnect_p(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
QObject *object = (QObject*)getPointer(L_p, 1);
|
void *pointer = getPointer(L_p, 1);
|
||||||
QString signalString = getVariant(L_p, 2).toString();
|
if (pointer != NULL) {
|
||||||
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
|
QObject *object = (QObject*)pointer;
|
||||||
if (signalIndex != -1) {
|
QString signalString = getVariant(L_p, 2).toString();
|
||||||
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
|
int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data());
|
||||||
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
|
if (signalIndex != -1) {
|
||||||
if (slotIndex != -1) {
|
LuaEngine *engine = (LuaEngine*)getPointer(L_p, "__LuaEngine");
|
||||||
QMetaMethod signal = object->metaObject()->method(signalIndex);
|
int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot_p()");
|
||||||
QMetaMethod slot = engine->metaObject()->method(slotIndex);
|
if (slotIndex != -1) {
|
||||||
QString funcStorage;
|
QMetaMethod signal = object->metaObject()->method(signalIndex);
|
||||||
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
|
QMetaMethod slot = engine->metaObject()->method(slotIndex);
|
||||||
pushVariant(L_p, funcStorage.toUtf8().data(), QVariant());
|
QString funcStorage;
|
||||||
QObject::disconnect(object, signal, engine, slot);
|
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