1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 09:57:14 +01:00

Fix issue in signal which could ommit to push a return value on the stack.

This commit is contained in:
Sandu Liviu Catalin 2016-11-13 14:06:53 +02:00
parent 5b159fba89
commit df12603405

View File

@ -1017,7 +1017,7 @@ protected:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Actual implementation of the consume method. * Actual implementation of the consume method.
*/ */
static SQInteger SqConsumeApproveImpl(HSQUIRRELVM vm, const SQBool rval) static SQInteger SqConsumeApproveImpl(HSQUIRRELVM vm, const SQBool rval, bool neg)
{ {
const Int32 top = sq_gettop(vm); const Int32 top = sq_gettop(vm);
// The signal instance // The signal instance
@ -1037,7 +1037,7 @@ protected:
return sq_throwerror(vm, "Invalid signal instance"); return sq_throwerror(vm, "Invalid signal instance");
} }
// Return value of each slot // Return value of each slot
SQBool ret = SQFalse; SQBool ret = !rval;
// Walk down the chain and trigger slots // Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next) for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{ {
@ -1076,12 +1076,12 @@ protected:
// Should we proceed to the next slot or stop here? // Should we proceed to the next slot or stop here?
if (ret == rval) if (ret == rval)
{ {
// Forward the returned value to the invoker
sq_pushbool(vm, ret);
// The slot satisfied our criteria // The slot satisfied our criteria
break; break;
} }
} }
// Forward the returned value to the invoker
sq_pushbool(vm, neg ? !ret : ret);
// Specify that we returned something // Specify that we returned something
return 1; return 1;
} }
@ -1093,7 +1093,7 @@ public:
*/ */
static SQInteger SqConsume(HSQUIRRELVM vm) static SQInteger SqConsume(HSQUIRRELVM vm)
{ {
return SqConsumeApproveImpl(vm, SQTrue); return SqConsumeApproveImpl(vm, SQTrue, false);
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
@ -1101,7 +1101,7 @@ public:
*/ */
static SQInteger SqApprove(HSQUIRRELVM vm) static SQInteger SqApprove(HSQUIRRELVM vm)
{ {
return SqConsumeApproveImpl(vm, SQFalse); return SqConsumeApproveImpl(vm, SQFalse, true);
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------