lua_settable(L, top_lvl2);
lua_pushstring(L, "name");
- lua_pushstring(L, game.name.c_str());
+ lua_pushstring(L, game.title.c_str());
+ lua_settable(L, top_lvl2);
+
+ lua_pushstring(L, "title");
+ lua_pushstring(L, game.title.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L, "author");
lua_newtable(L);
int table2 = lua_gettop(L);
int internal_index = 1;
- for (const std::string &addon_mods_path : game.addon_mods_paths) {
+ for (const auto &addon_mods_path : game.addon_mods_paths) {
lua_pushnumber(L, internal_index);
- lua_pushstring(L, addon_mods_path.c_str());
+ lua_pushstring(L, addon_mods_path.second.c_str());
lua_settable(L, table2);
internal_index++;
}
lua_pushstring(L, spec.author.c_str());
lua_setfield(L, -2, "author");
+ if (!spec.title.empty()) {
+ lua_pushstring(L, spec.title.c_str());
+ lua_setfield(L, -2, "title");
+ }
+
lua_pushinteger(L, spec.release);
lua_setfield(L, -2, "release");
const char *name = luaL_checkstring(L, 1);
int gameidx = luaL_checkinteger(L,2) -1;
+ StringMap use_settings;
+ luaL_checktype(L, 3, LUA_TTABLE);
+ lua_pushnil(L);
+ while (lua_next(L, 3) != 0) {
+ // key at index -2 and value at index -1
+ use_settings[luaL_checkstring(L, -2)] = luaL_checkstring(L, -1);
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+
std::string path = porting::path_user + DIR_DELIM
"worlds" + DIR_DELIM
+ sanitizeDirName(name, "world_");
std::vector<SubgameSpec> games = getAvailableGames();
+ if (gameidx < 0 || gameidx >= (int) games.size()) {
+ lua_pushstring(L, "Invalid game index");
+ return 1;
+ }
+
+ // Set the settings for world creation
+ // this is a bad hack but the best we have right now..
+ StringMap backup;
+ for (auto it : use_settings) {
+ if (g_settings->existsLocal(it.first))
+ backup[it.first] = g_settings->get(it.first);
+ g_settings->set(it.first, it.second);
+ }
- if ((gameidx >= 0) &&
- (gameidx < (int) games.size())) {
+ // Create world if it doesn't exist
+ try {
+ loadGameConfAndInitWorld(path, name, games[gameidx], true);
+ lua_pushnil(L);
+ } catch (const BaseException &e) {
+ auto err = std::string("Failed to initialize world: ") + e.what();
+ lua_pushstring(L, err.c_str());
+ }
- // Create world if it doesn't exist
- try {
- loadGameConfAndInitWorld(path, name, games[gameidx], true);
- lua_pushnil(L);
- } catch (const BaseException &e) {
- lua_pushstring(L, (std::string("Failed to initialize world: ") + e.what()).c_str());
- }
- } else {
- lua_pushstring(L, "Invalid game index");
+ // Restore previous settings
+ for (auto it : use_settings) {
+ auto it2 = backup.find(it.first);
+ if (it2 == backup.end())
+ g_settings->remove(it.first); // wasn't set before
+ else
+ g_settings->set(it.first, it2->second); // was set before
}
+
return 1;
}
/******************************************************************************/
int ModApiMainMenu::l_get_modpaths(lua_State *L)
{
- int index = 1;
lua_newtable(L);
+
ModApiMainMenu::l_get_modpath(L);
- lua_rawseti(L, -2, index);
+ lua_setfield(L, -2, "mods");
+
for (const std::string &component : getEnvModPaths()) {
- index++;
lua_pushstring(L, component.c_str());
- lua_rawseti(L, -2, index);
+ lua_setfield(L, -2, fs::AbsolutePath(component).c_str());
}
return 1;
}