Exemple #1
0
void test_varlist()
{
	VarList args;	
	args.add(1);
	args.add("ddddd");
	args.add(true);
	printf("args count: %d\n", args.count());
	printf("args 0: %d\n", args.get(0).toInt());
	printf("args 1: %s\n", args.get(1).toString());
	printf("args 2: %s\n", args.get(2).toBool() ? "true" : "false");
}
Exemple #2
0
void OptionsTabApplication::restoreOptions()
{
	if ( !w )
		return;

	OptApplicationUI *d = (OptApplicationUI *)w;

	d->ck_autoUpdate->setChecked(PsiOptions::instance()->getOption("options.auto-update.check-on-startup").toBool());
	d->ck_quitOnClose->setChecked(PsiOptions::instance()->getOption("options.ui.contactlist.quit-on-close").toBool());

	// docklet
	d->ck_docklet->setChecked( PsiOptions::instance()->getOption("options.ui.systemtray.enable").toBool() );
	d->ck_dockDCstyle->setChecked( PsiOptions::instance()->getOption("options.ui.systemtray.use-double-click").toBool() );
	d->ck_dockHideMW->setChecked( PsiOptions::instance()->getOption("options.contactlist.hide-on-start").toBool() );
	d->ck_dockToolMW->setChecked( PsiOptions::instance()->getOption("options.contactlist.use-toolwindow").toBool() );
	doEnableQuitOnClose(d->ck_docklet->isChecked()?1:0);

	// data transfer
	d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
	d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );

	// Language
	VarList vList = TranslationManager::instance()->availableTranslations();
	QStringList lang = vList.varsToStringList();
	d->cb_lang->addItem(tr("Default"));
	foreach(QString item, lang) {
		d->cb_lang->addItem(vList.get(item));
	}
Exemple #3
0
void ScriptEngine::callEvent( const char *name, const VarList &args, VarList &result )
{
    FUNCTION_MAP::iterator it = m_functionMap.find(name);
    if (it != m_functionMap.end())
    {
        LUA_FUNCTION nHandler = it->second;

        LuaHelper::getRefFunction(m_luaState, nHandler);
        if (lua_isfunction(m_luaState, -1))
        {
            size_t count = args.count();
            for (size_t i=0; i<count; ++i)
            {
                int type = args.get(i).getType();
                switch (type)
                {
                case Var::BOOL:
                    lua_pushboolean(m_luaState, args.get(i).toBool() ? 1 : 0);
                    break;
                case Var::BYTE:
                case Var::SHORT:
                case Var::INT:
                case Var::INT64:
                case Var::FLOAT:
                case Var::NUMBER:
                    lua_pushnumber(m_luaState, args.get(i).toNumber());
                    break;
                case Var::STRING:
                    lua_pushstring(m_luaState, args.get(i).toString());
                    break;
                default:
                    break;
                }
            }
            int error = lua_pcall(m_luaState, args.count(), 1, NULL);
            if (error)
            {
                printf("[LUA ERROR] %s\n", lua_tostring(m_luaState, - 1));
                lua_pop(m_luaState, 1); // remove error message from stack
            }
            else
            {
                // get return value
                if (lua_isnumber(m_luaState, -1))
                {
                    int ret = lua_tointeger(m_luaState, -1);
                    result.add(ret);
                }
                else if (lua_isboolean(m_luaState, -1))
                {
                    int ret = lua_toboolean(m_luaState, -1);
                    result.add(ret);
                }
                else if (lua_isstring(m_luaState, -1))
                {
                    const char *ret = lua_tostring(m_luaState, -1);
                    result.add(ret);
                }

                // remove return value from stack
                lua_pop(m_luaState, 1);
            }
        }

    }
}