Example #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);
    }
 }
Example #2
0
 void CLuaController::Reset() {
    if(m_bScriptActive) {
       if(m_bIsOK) {
          m_bIsOK = CLuaUtility::CallLuaFunction(m_ptLuaState, "reset");
       }
       else {
          SetLuaScript(m_strScriptFileName);
       }
    }
 }
Example #3
0
std::string SzbaseWrapper::add_param( const std::string& param
									, const std::string& base
									, const std::string& formula
									, const std::string& token
									, const std::string& type
									, int prec
									, unsigned start_time)
	throw( szbase_invalid_name , szbase_formula_invalid_syntax, szbase_init_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	std::wstring _param = convert_string( param );
	std::wstring _token = convert_string( token );
	std::wstring _formula = convert_string( formula );

	std::wstring new_param_name;
	if ( !create_param_name( _param , _token , new_param_name ) )
		throw szbase_invalid_name(param + " in not valid user defined param name");

	std::vector<std::wstring> strings;
	if( !extract_strings_from_formula( _formula , strings ) )
		throw szbase_formula_invalid_syntax("formula cannot be parsed");

	for( auto& param : strings )
	{
		std::wstring new_name;
		if ( !create_param_name_in_formula( param , _token , new_name ) )
				continue;

		auto i = _formula.find( param );
		assert( i != std::wstring::npos );	

		_formula.replace( i , param.size() , new_name );
	}

	TParam::FormulaType formula_type;
	if( type == "av" )
		formula_type = TParam::LUA_AV;
	else if( type == "va" )
		formula_type = TParam::LUA_VA;

	auto tparam = new TParam(NULL, NULL, L"", formula_type, TParam::P_LUA);
	tparam->SetName(new_param_name);
	tparam->SetPrec(prec);
	tparam->SetTimeType(TParam::NANOSECOND); ///XXX:
	tparam->SetLuaScript(SC::S2U(_formula).c_str());
	tparam->SetLuaStartDateTime(start_time);

	IPKContainer::GetObject()->AddExtraParam( convert_string ( base ) , tparam );

	return reinterpret_cast<const char*>(SC::S2U(new_param_name).c_str());
}
Example #4
0
 void CLuaController::SetLuaScript(const std::string& str_script) {
    TConfigurationNode t_tree;
    SetLuaScript(str_script, t_tree);
 }