void SpaceStationType::Init() { assert(s_lua == 0); if (s_lua != 0) return; s_lua = luaL_newstate(); lua_State *L = s_lua; LUA_DEBUG_START(L); pi_lua_open_standard_base(L); LuaVector::Register(L); LUA_DEBUG_CHECK(L, 0); lua_register(L, "define_orbital_station", define_orbital_station); lua_register(L, "define_surface_station", define_surface_station); namespace fs = FileSystem; for (fs::FileEnumerator files(fs::gameDataFiles, "stations", fs::FileEnumerator::Recurse); !files.Finished(); files.Next()) { const fs::FileInfo &info = files.Current(); if (ends_with_ci(info.GetPath(), ".lua")) { const std::string name = info.GetName(); s_currentStationFile = name.substr(0, name.size()-4); pi_lua_dofile(L, info.GetPath()); s_currentStationFile.clear(); } } LUA_DEBUG_END(L, 0); }
void CustomSystem::Init() { lua_State *L = luaL_newstate(); LUA_DEBUG_START(L); pi_lua_open_standard_base(L); LuaVector::Register(L); LuaFixed::Register(L); LuaConstants::Register(L); // create a shortcut f = fixed.new lua_getglobal(L, LuaFixed::LibName); lua_getfield(L, -1, "new"); assert(lua_iscfunction(L, -1)); lua_setglobal(L, "f"); lua_pop(L, 1); // pop the fixed table // provide shortcut vector constructor: v = vector.new lua_getglobal(L, LuaVector::LibName); lua_getfield(L, -1, "new"); assert(lua_iscfunction(L, -1)); lua_setglobal(L, "v"); lua_pop(L, 1); // pop the vector table LUA_DEBUG_CHECK(L, 0); RegisterCustomSystemsAPI(L); LUA_DEBUG_CHECK(L, 0); pi_lua_dofile_recursive(L, "systems"); LUA_DEBUG_END(L, 0); lua_close(L); }
LuaManager::LuaManager() : m_lua(NULL) { if (instantiated) { fprintf(stderr, "Can't instantiate more than one LuaManager"); abort(); } m_lua = luaL_newstate(); pi_lua_open_standard_base(m_lua); lua_atpanic(m_lua, pi_lua_panic); instantiated = true; }
//static void Faction::Init() { lua_State *L = luaL_newstate(); LUA_DEBUG_START(L); pi_lua_open_standard_base(L); LuaConstants::Register(L); LUA_DEBUG_CHECK(L, 0); RegisterFactionsAPI(L); LUA_DEBUG_CHECK(L, 0); pi_lua_dofile_recursive(L, "factions"); LUA_DEBUG_END(L, 0); lua_close(L); printf("Number of factions added: " SIZET_FMT "\n", s_factions.size()); StarSystem::ShrinkCache(); // clear the star system cache of anything we used for faction generation }
void FactionsDatabase::Init() { lua_State *L = luaL_newstate(); LUA_DEBUG_START(L); pi_lua_open_standard_base(L); LuaConstants::Register(L); LUA_DEBUG_CHECK(L, 0); RegisterFactionsAPI(L); LUA_DEBUG_CHECK(L, 0); pi_lua_dofile_recursive(L, "factions"); LUA_DEBUG_END(L, 0); lua_close(L); Output("Number of factions added: " SIZET_FMT "\n", m_factions.size()); ClearHomeSectors(); Pi::FlushCaches(); // clear caches of anything we used for faction generation while (!m_missingFactionsMap.empty()) { const std::string& factionName = m_missingFactionsMap.begin()->first; std::list<CustomSystem*>& csl = m_missingFactionsMap.begin()->second; while (!csl.empty()) { CustomSystem* cs = csl.front(); // FIXME: How to signal missing faction? fprintf(stderr, "Custom system %s referenced unknown faction %s\n", cs->name.c_str(), factionName.c_str()); csl.pop_front(); } m_missingFactionsMap.erase(m_missingFactionsMap.begin()); } m_initialized = true; SetHomeSectors(); }