Beispiel #1
0
/**
    Initializes everything in hopmod. This function is called at server startup and server reload.
*/
void init_hopmod()
{
    main_thread = boost::this_thread::get_id();

    signal_shutdown.connect(boost::bind(&shutdown_lua));
    signal_shutdown.connect(&cleanup_info_files_on_shutdown);
    
    info_file("log/sauer_server.pid", "%i\n", getpid());
    
    init_lua();
    
    static const char * INIT_SCRIPT = "script/init.lua";
    
    lua_State * L = get_lua_state();
    if(luaL_loadfile(L, INIT_SCRIPT) == 0)
    {
        event_listeners().add_listener("init"); // Take the value of the top of the stack to add
        // to the init listeners table
    }
    else
    {
        std::cerr<<"error during initialization: "<<lua_tostring(L, -1)<<std::endl;
        lua_pop(L, 1);
    }
    
    event_init(event_listeners(), boost::make_tuple());
}
int load_primary_config( const char *aFileName )
{
  // We only want to have ONE state object for the primary config.
  lua_State *lLuaState = get_lua_state( );

  if( lLuaState != NULL )
    {
      _handleLuaResult( luaL_loadfile( lLuaState, aFileName ),
                        _L_FILE_LOAD_FAILURE );
      return 0;

    _L_FILE_LOAD_FAILURE:
      printf( "File '%s' failed to load!\n", aFileName );
      goto _L_FAILURE;
    }
  else
    {
    _L_FAILURE:
      // TODO > set a library error code...?
      return -1;
    }
}