Example #1
0
bool CScriptSystem::ExecuteString(const char* sBuffer, bool useEnv)
{
    SCRIPT_STACK_GUARD(m_pLS);
    PushErrorHandler(m_pLS);
    int nRes = luaL_loadstring(m_pLS, sBuffer);

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    if (useEnv)
    {
        lua_getref(m_pLS, m_environmentTable);
        lua_setfenv(m_pLS, -2);
    }

    nRes = lua_pcall(m_pLS, 0, 0, -2);

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    return true;
}
Example #2
0
bool CScriptSystem::ExecuteBuffer(const char* sBuffer, int nSize, const char* name, bool useEnv)
{
    SCRIPT_STACK_GUARD(m_pLS);
    PushErrorHandler(m_pLS);
    int nRes = luaL_loadbuffer(m_pLS, sBuffer, nSize, name ? name : "__script_buffer__");

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    if (useEnv)
    {
        lua_getref(m_pLS, m_environmentTable);
        lua_setfenv(m_pLS, -2);
    }

    nRes = lua_pcall(m_pLS, 0, 0, -2);

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    return true;
}
Example #3
0
bool CScriptSystem::_ExecuteFile(const char* sFileName)
{
    SCRIPT_STACK_GUARD(m_pLS);
    PushErrorHandler(m_pLS);
    int nRes = luaL_loadfile(m_pLS, sFileName);

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    nRes = lua_pcall(m_pLS, 0, 0, -2);

    if (nRes)
    {
        HandleErrorCode(m_pLS, nRes);
        return false;
    }

    return true;
}
Example #4
0
bool CScriptSystem::ExecuteFunction(lua_State* L, int nargs, int nresults)
{
    int errfunc = -(nargs + 2);
    PushErrorHandler(L);
    lua_insert(L, errfunc);
    int nRes = lua_pcall(L, nargs, nresults, errfunc);

    if (nRes)
    {
        HandleErrorCode(L, nRes);
        return false;
    }

    lua_remove(L, -(nresults + 1));
    return true;
}
Example #5
0
int _tmain(int argc, LPTSTR* argv)
{
	g_errorCode = ERROR_NONE;

	switch (ParseCallerParameters(argc, argv))
	{
	case REQUEST_REGISTER:
		g_errorCode = RegisterService(L"FileChecker", L"File Checker");
		break;

	case REQUEST_UNREGISTER:
		g_errorCode = UnregisterService(L"FileChecker");
		break;

	case REQUEST_RUN:
		RunService();
		break;

	default:
		g_errorCode = ERROR_INVALID_REQUEST;
	}

	return HandleErrorCode(g_errorCode);
}
Example #6
0
void MpvHandler::Command(const char *args[])
{
    HandleErrorCode(mpv_command(mpv, args));
}
Example #7
0
void MpvHandler::SetOption(QString key, QString val)
{
    QByteArray tmp1 = key.toUtf8(),
               tmp2 = val.toUtf8();
    HandleErrorCode(mpv_set_option_string(mpv, tmp1.constData(), tmp2.constData()));
}
Example #8
0
void MpvHandler::Deinterlace(bool deinterlace)
{
    HandleErrorCode(mpv_set_property_string(mpv, "deinterlace", deinterlace ? "yes" : "auto"));
    ShowText(tr("Deinterlacing: %0").arg(deinterlace ? tr("enabled") : tr("disabled")));
}
Example #9
0
bool MpvHandler::event(QEvent *event)
{
    if(event->type() == QEvent::User)
    {
        while(mpv)
        {
            mpv_event *event = mpv_wait_event(mpv, 0);
            if(event == nullptr ||
               event->event_id == MPV_EVENT_NONE)
            {
                break;
            }
            HandleErrorCode(event->error);
            switch (event->event_id)
            {
            case MPV_EVENT_PROPERTY_CHANGE:
            {
                mpv_event_property *prop = (mpv_event_property*)event->data;
                if(QString(prop->name) == "playback-time") // playback-time does the same thing as time-pos but works for streaming media
                {
                    if(prop->format == MPV_FORMAT_DOUBLE)
                    {
                        setTime((int)*(double*)prop->data);
                        lastTime = time;
                    }
                }
                else if(QString(prop->name) == "volume")
                {
                    if(prop->format == MPV_FORMAT_DOUBLE)
                        setVolume((int)*(double*)prop->data);
                }
                else if(QString(prop->name) == "sid")
                {
                    if(prop->format == MPV_FORMAT_INT64)
                        setSid(*(int*)prop->data);
                }
                else if(QString(prop->name) == "aid")
                {
                    if(prop->format == MPV_FORMAT_INT64)
                        setAid(*(int*)prop->data);
                }
                else if(QString(prop->name) == "sub-visibility")
                {
                    if(prop->format == MPV_FORMAT_FLAG)
                        setSubtitleVisibility((bool)*(unsigned*)prop->data);
                }
                else if(QString(prop->name) == "mute")
                {
                    if(prop->format == MPV_FORMAT_FLAG)
                        setMute((bool)*(unsigned*)prop->data);
                }
                else if(QString(prop->name) == "core-idle")
                {
                    if(prop->format == MPV_FORMAT_FLAG)
                    {
                        if((bool)*(unsigned*)prop->data && playState == Mpv::Playing)
                            ShowText(tr("Buffering..."), 0);
                        else
                            ShowText(QString(), 0);
                    }
                }
                else if(QString(prop->name) == "paused-for-cache")
                {
                    if(prop->format == MPV_FORMAT_FLAG)
                    {
                        if((bool)*(unsigned*)prop->data && playState == Mpv::Playing)
                            ShowText(tr("Your network is slow or stuck, please wait a bit"), 0);
                        else
                            ShowText(QString(), 0);
                    }
                }
                break;
            }
            case MPV_EVENT_IDLE:
                fileInfo.length = 0;
                setTime(0);
                setPlayState(Mpv::Idle);
                break;
                // these two look like they're reversed but they aren't. the names are misleading.
            case MPV_EVENT_START_FILE:
                setPlayState(Mpv::Loaded);
                break;
            case MPV_EVENT_FILE_LOADED:
                setPlayState(Mpv::Started);
                LoadFileInfo();
                SetProperties();
            case MPV_EVENT_UNPAUSE:
                setPlayState(Mpv::Playing);
                break;
            case MPV_EVENT_PAUSE:
                setPlayState(Mpv::Paused);
                ShowText(QString(), 0);
                break;
            case MPV_EVENT_END_FILE:
                if(playState == Mpv::Loaded)
                    ShowText(tr("File couldn't be opened"));
                setPlayState(Mpv::Stopped);
                break;
            case MPV_EVENT_SHUTDOWN:
                QCoreApplication::quit();
                break;
            case MPV_EVENT_LOG_MESSAGE:
            {
                mpv_event_log_message *message = static_cast<mpv_event_log_message*>(event->data);
                if(message != nullptr)
                    emit messageSignal(message->text);
                break;
            }
            default: // unhandled events
                break;
            }
        }
        return true;
    }
    return QObject::event(event);
}