engine/scripting/source/MapScript.cpp
// Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully false otherwise .
bool MapScript::execute(ScriptEngine& se, const string& map_script, MapPtr map)
{
  if (map_script.empty())
  {
    return false;
  }
  bool result = true;
  string map_id;
  if (map != nullptr)
  {
    map_id = map->get_map_id();
  }
  if (se.execute(map_script, {{"map_id", map_id}}))
  {
    lua_State* L = se.get_current_state();
    lua_getglobal(L, MAP_MODULE_NAME.c_str());
    lua_getfield(L, -1, MAP_FUNCTION_NAME.c_str());
    lua_pushstring(L, map_id.c_str());
    if (lua_pcall(L, 1, 0, 0) != 0)
    {
      string l_err = lua_tostring(L, -1);
      string error_msg = "MapScript::execute - error running Lua function `" + MAP_FUNCTION_NAME + "': " + l_err;
      Log::instance().error(error_msg);
      lua_pop(L, 1);
      result = false;
    }
  }
  else
  {
    Log::instance().error("MapScript::execute - did not run Lua function due to script failure: " + map_script);
    result = false;
  }
  return result;
}
bool MapScript :: execute ( ScriptEngine & se , const string & map_script , MapPtr map ) { if ( map_script . empty ( ) ) { return false ; } bool result = true ; string map_id ; if ( map != nullptr ) { map_id = map -> get_map_id ( ) ; } if ( se . execute ( map_script , { { " " , map_id } } ) ) { lua_State * L = se . get_current_state ( ) ; lua_getglobal ( L , MAP_MODULE_NAME . c_str ( ) ) ; lua_getfield ( L , -1 , MAP_FUNCTION_NAME . c_str ( ) ) ; lua_pushstring ( L , map_id . c_str ( ) ) ; if ( lua_pcall ( L , 1 , 0 , 0 ) != 0 ) { string l_err = lua_tostring ( L , -1 ) ; string error_msg = " " + MAP_FUNCTION_NAME + " " + l_err ; Log :: instance ( ) . error ( error_msg ) ; lua_pop ( L , 1 ) ; result = false ; } } else { Log :: instance ( ) . error ( " " + map_script ) ; result = false ; } return result ; }
Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully false otherwise .
// Set up the function call parameters. // Do the function call.  The "init_map" function returns nothing.