Example #1
0
static SQInteger notifyAllExceptions(HSQUIRRELVM v)
{
	SQBool enable;
	sq_tobool(v, 1, &enable);
	sq_notifyallexceptions(v, enable != SQFalse);
	return SQ_OK;
}
Example #2
0
static SQInteger class_rawnewmember(HSQUIRRELVM v)
{
	SQInteger top = sq_gettop(v);
	SQBool bstatic = SQFalse;
	if(top == 5)
	{
		sq_tobool(v,-1,&bstatic);
		sq_pop(v,1);
	}

	if(top < 4) {
		sq_pushnull(v);
	}
	return SQ_SUCCEEDED(sq_rawnewmember(v,-4,bstatic))?1:SQ_ERROR;
}
Example #3
0
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqApprove(HSQUIRRELVM vm)
{
    const Int32 top = sq_gettop(vm);
    // The signal instance
    Signal * signal = nullptr;
    // Attempt to extract the signal instance
    try
    {
        signal = Var< Signal * >(vm, 1).value;
    }
    catch (const Sqrat::Exception & e)
    {
        return sq_throwerror(vm, e.what());
    }
    // Do we have a valid signal instance?
    if (!signal)
    {
        return sq_throwerror(vm, "Invalid signal instance");
    }
    // Default to approved
    SQBool ret = SQTrue;
    // Walk down the chain and trigger slots
    for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
    {
        // Grab the next node upfront
        next = node->mNext;
        // Remember the current stack size
        const StackGuard sg(vm);
        // Push the callback object
        sq_pushobject(vm, node->mFuncRef);
        // Is there an explicit environment?
        if (sq_isnull(node->mEnvRef))
        {
            sq_pushroottable(vm);
        }
        else
        {
            sq_pushobject(vm, node->mEnvRef);
        }
        // Are there any parameters to forward?
        if (top > 1)
        {
            for (SQInteger i = 2; i <= top; ++i)
            {
                sq_push(vm, i);
            }
        }
        // Make the function call and store the result
        const SQRESULT res = sq_call(vm, top, true, ErrorHandling::IsEnabled());
        // Validate the result
        if (SQ_FAILED(res))
        {
            return res; // Propagate the error
        }
        // Is the returned value not null?
        else if (sq_gettype(vm, -1) != OT_NULL)
        {
            // Obtain the returned value
            sq_tobool(vm, -1, &ret);
            // Should we proceed to the next slot or stop here?
            if (ret == SQFalse)
            {
                break; // The slot did not approve the signal
            }
        }
    }
    // Forward the returned value to the invoker
    sq_pushbool(vm, ret);
    // Specify that we returned something
    return 1;
}