Esempio n. 1
0
 void CLuaController::Init(TConfigurationNode& t_tree) {
    try {
       /* Create RNG */
       m_pcRNG = CRandom::CreateRNG("argos");
       /* Load script */
       std::string strScriptFileName;
       GetNodeAttributeOrDefault(t_tree, "script", strScriptFileName, strScriptFileName);
       if(strScriptFileName != "") {
          SetLuaScript(strScriptFileName, t_tree);
          if(! m_bIsOK) {
             THROW_ARGOSEXCEPTION("Error loading Lua script \"" << strScriptFileName << "\": " << lua_tostring(m_ptLuaState, -1));
          }
       }
       else {
          /* Create a new Lua stack */
          m_ptLuaState = luaL_newstate();
          /* Load the Lua libraries */
          luaL_openlibs(m_ptLuaState);
          /* Create and set Lua state */
          CreateLuaState();
          SensorReadingsToLuaState();
       }
    }
    catch(CARGoSException& ex) {
       THROW_ARGOSEXCEPTION_NESTED("Error initializing Lua controller", ex);
    }
 }
Esempio n. 2
0
 void CLuaController::SetLuaScript(const std::string& str_script,
                                   TConfigurationNode& t_tree) {
    /* First, delete old script */
    if(m_bScriptActive) {
       lua_close(m_ptLuaState);
       m_bScriptActive = false;
       m_strScriptFileName = "";
    }
    /* Create a new Lua stack */
    m_ptLuaState = luaL_newstate();
    /* Load the Lua libraries */
    luaL_openlibs(m_ptLuaState);
    /* Load script */
    if(!CLuaUtility::LoadScript(m_ptLuaState, str_script)) {
       m_bIsOK = false;
       return;
    }
    m_strScriptFileName = str_script;
    /* Create and set variables */
    CreateLuaState();
    SensorReadingsToLuaState();
    ParametersToLuaState(t_tree);
    /* Execute script init function */
    if(!CLuaUtility::CallLuaFunction(m_ptLuaState, "init")) {
       m_bIsOK = false;
       return;
    }
    m_bIsOK = true;
    m_bScriptActive = true;
 }
Esempio n. 3
0
bool BaseVMLua::Initialize() {
	_pGlobalState = CreateLuaState(_pOpaque);
	if (_pGlobalState == NULL) {
		FATAL("Unable to initialize lua virtual machine");
		return false;
	}
	return true;
}
Esempio n. 4
0
bool ReadLuaString(string script, string section, Variant &configuration) {
	lua_State *pLuaState = CreateLuaState(NULL);

	if (!LoadLuaScriptFromString(script, pLuaState)) {
		DestroyLuaState(pLuaState);
		return false;
	}

	bool res = ReadLuaState(pLuaState, section, configuration);
	DestroyLuaState(pLuaState);
	return res;
}
Esempio n. 5
0
Engine::Engine()
{
    Sanguosha = this;

    lua = CreateLuaState();
    if (!DoLuaScript(lua, "lua/config.lua")) exit(1);

    QStringList stringlist_sp_convert = GetConfigFromLuaState(lua, "convert_pairs").toStringList();
    foreach (QString cv_pair, stringlist_sp_convert) {
        QStringList pairs = cv_pair.split("->");
        QStringList cv_to = pairs.at(1).split("|");
        foreach (QString to, cv_to)
            sp_convert_pairs.insertMulti(pairs.at(0), to);
    }
Esempio n. 6
0
Engine::Engine()
{
    Sanguosha = this;

    lua = CreateLuaState();
    DoLuaScript(lua, "lua/config.lua");

    QStringList package_names = GetConfigFromLuaState(lua, "package_names").toStringList();
    foreach(QString name, package_names)
        if(name != "ThreeKingdoms")
            addPackage(name);

    addPackage("ThreeKingdoms");

    QStringList scene_names = GetConfigFromLuaState(lua, "scene_names").toStringList();
    foreach(QString name, scene_names)
        addScenario(name);

    DoLuaScript(lua, "lua/sanguosha.lua");

    // available game modes
    modes["02p"] = tr("2 players");
    //modes["02pbb"] = tr("2 players (using blance beam)");
    modes["02_1v1"] = tr("2 players (KOF style)");
    modes["03p"] = tr("3 players");
    modes["03_3kingdoms"] = tr("3 players(3 kingdoms mode)");
    modes["04p"] = tr("4 players");
    modes["04_1v3"] = tr("4 players (Hulao Pass)");
    modes["05p"] = tr("5 players");
    modes["06p"] = tr("6 players");
    modes["06_3v3"] = tr("6 players (3v3)");
    modes["06pd"] = tr("6 players (2 renegades)");
    modes["07p"] = tr("7 players");
    modes["08p"] = tr("8 players");
    modes["08pd"] = tr("8 players (2 renegades)");
    modes["08pz"] = tr("8 players (0 renegade)");
    modes["09p"] = tr("9 players");
    modes["10pd"] = tr("10 players");
    modes["10p"] = tr("10 players (1 renegade)");
    modes["10pz"] = tr("10 players (0 renegade)");

    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(deleteLater()));



    foreach(QString ban, getBanPackages()){
        addBanPackage(ban);
    }
Esempio n. 7
0
Engine::Engine()
{
    Sanguosha = this;

    lua = CreateLuaState();
    DoLuaScript(lua, "lua/config.lua");

    QStringList package_names = GetConfigFromLuaState(lua, "package_names").toStringList();
    foreach(QString name, package_names)
        addPackage(name);

    QStringList scene_names = GetConfigFromLuaState(lua, "scene_names").toStringList();
    foreach(QString name, scene_names)
        addScenario(name);

    DoLuaScript(lua, "lua/sanguosha.lua");

    // available game modes
    modes["02p"] = tr("2 players");
    //modes["02pbb"] = tr("2 players (using blance beam)");
    modes["02_1v1"] = tr("2 players (KOF style)");
    modes["03p"] = tr("3 players");
    modes["04p"] = tr("4 players");
    modes["04_1v3"] = tr("4 players (Hulao Pass)");
    modes["05p"] = tr("5 players");
    modes["05_2v3"] = tr("5 players (Changban Slope)");
    modes["06p"] = tr("6 players");
    modes["06pd"] = tr("6 players (2 renegades)");
    modes["06_3v3"] = tr("6 players (3v3)");
    modes["07p"] = tr("7 players");
    modes["08p"] = tr("8 players");
    modes["08pd"] = tr("8 players (2 renegades)");
    modes["08pz"] = tr("8 players (0 renegade)");
    modes["09p"] = tr("9 players");
    modes["10pd"] = tr("10 players");
    modes["10p"] = tr("10 players (1 renegade)");
    modes["10pz"] = tr("10 players (0 renegade)");

    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(deleteLater()));

    foreach(QString ban, getBanPackages())
        addBanPackage(ban);

    foreach(const Skill *skill, skills.values()){
        Skill *mutable_skill = const_cast<Skill *>(skill);
        mutable_skill->initMediaSource();
    }
}