示例#1
0
void sq_setdebughook(HSQUIRRELVM v)
{
	SQObject o = stack_get(v,-1);
	if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
		v->_debughook = o;
		v->Pop();
	}
}
示例#2
0
void sq_seterrorhandler(HSQUIRRELVM v)
{
	SQObject o = stack_get(v, -1);
	if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
		v->_errorhandler = o;
		v->Pop();
	}
}
示例#3
0
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqQuery(HSQUIRRELVM vm)
{
    const Int32 top = sq_gettop(vm);
    // Do we have the collector environment?
    if (top <= 1)
    {
        return sq_throwerror(vm, "Missing collector environment");
    }
    // Do we have the collector function?
    else if (top <= 2)
    {
        return sq_throwerror(vm, "Missing collector callback");
    }
    // The signal instance
    Signal * signal = nullptr;
    // Attempt to extract the signal instance and collector
    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");
    }
    // The collector
    HSQOBJECT cenv, cfunc;
    // Grab the collector environment
    SQRESULT res = sq_getstackobj(vm, 2, &cenv);
    // Validate the result
    if (SQ_FAILED(res))
    {
        return res; // Propagate the error
    }
    // Was there a valid environment?
    else if (sq_isnull(cenv))
    {
        // Remember the current stack size
        const StackGuard sg(vm);
        // Default to the root table
        sq_pushroottable(vm);
        // Try to grab the collector environment again
        SQRESULT res = sq_getstackobj(vm, -1, &cenv);
        // Validate the result
        if (SQ_FAILED(res))
        {
            return res; // Propagate the error
        }
    }
    // Grab the collector function
    res = sq_getstackobj(vm, 3, &cfunc);
    // Validate the result
    if (SQ_FAILED(res))
    {
        return res; // Propagate the error
    }
    // Some dummy checks to make sure the collector is a callable object
    else if (!sq_isfunction(cfunc) && !sq_isclosure(cfunc) && !sq_isnativeclosure(cfunc))
    {
        return sq_throwerror(vm, "Invalid collector");
    }
    // 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 > 3)
        {
            for (SQInteger i = 4; i <= top; ++i)
            {
                sq_push(vm, i);
            }
        }
        // Make the function call and store the result
        res = sq_call(vm, top - 2, true, ErrorHandling::IsEnabled());
        // Validate the result
        if (SQ_FAILED(res))
        {
            return res; // Propagate the error
        }
        // Push the collector onto the stack
        sq_pushobject(vm, cfunc);
        sq_pushobject(vm, cenv);
        // Push the returned value
        sq_push(vm, -3);
        // Make the function call and store the result
        res = sq_call(vm, 2, false, ErrorHandling::IsEnabled());
        // Validate the result
        if (SQ_FAILED(res))
        {
            return res; // Propagate the error
        }
    }
    // Specify that we don't return anything
    return 0;
}