instead_lang and snapshots

This commit is contained in:
p.kosyh 2010-07-15 06:59:57 +00:00
parent 3167b2f77d
commit d612917017
9 changed files with 68 additions and 12 deletions

4
debian/changelog vendored
View file

@ -35,7 +35,9 @@ instead (1.2.0) unstable; urgency=low
* self() is now self;
* no return goto needed;
* disable_all/enable_all for lists;
* purge and list_purge
* purge and list_purge;
* undocumented gamefile;
* undocumented LANG;
* many bugfixes...
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 06 Jul 2010 14:09:00 +0300

View file

@ -104,14 +104,13 @@ int game_select(const char *name)
return 0;
}
static char *game_name(const char *path, const char *d_name)
{
char *l;
char *p = getfilepath(path, MAIN_FILE);
if (!p)
goto err;
l = lookup_tag(p, "Name", "--");
l = lookup_lang_tag(p, "Name", "--");
free(p);
if (l)
return l;
@ -119,6 +118,21 @@ err:
return strdup(d_name);
}
int games_rename(void)
{
int i;
char cwd[PATH_MAX];
getcwd(cwd, sizeof(cwd));
chdir(game_cwd);
for (i = 0; i < games_nr; i++) {
FREE(games[i].name);
games[i].name = game_name(games[i].path, games[i].dir);
}
chdir(cwd);
return 0;
}
static int cmp_game(const void *p1, const void *p2)
{
const struct game *g1 = (const struct game*)p1;

View file

@ -43,6 +43,7 @@ extern int game_change_hz(int hz);
extern int games_lookup(const char *path);
extern int games_remove(int nr);
extern int games_replace(const char *path, const char *dir);
extern int games_rename(void);
extern void game_err_msg(const char *s);
extern int game_error(const char *name);

View file

@ -411,6 +411,19 @@ static const luaL_Reg base_funcs[] = {
{NULL, NULL}
};
int instead_lang(void)
{
char lang[64];
if (!L)
return 0;
if (opt_lang && *opt_lang)
snprintf(lang, sizeof(lang) - 1, "LANG='%s'", opt_lang);
else
snprintf(lang, sizeof(lang) - 1, "LANG='en'");
instead_eval(lang); instead_clear();
return 0;
}
static int instead_package(void)
{
char *p;
@ -452,6 +465,7 @@ int instead_init(void)
luaL_register(L, "_G", base_funcs);
instead_package();
instead_lang();
if (dofile(L,STEAD_PATH"/stead.lua")) {
return -1;

View file

@ -10,6 +10,7 @@ extern int instead_clear(void);
extern char *instead_retval(int n);
extern int instead_bretval(int n);
extern int instead_iretval(int n);
extern int instead_lang(void);
char *fromgame(const char *s);
extern int instead_encode(const char *s, const char *d);
#endif

View file

@ -588,7 +588,10 @@ int game_menu_act(const char *a)
if (cur_lang >= langs_nr)
cur_lang = 0;
} while (menu_lang_select(langs[cur_lang].file));
if (curgame_dir)
instead_lang();
themes_rename();
games_rename();
game_menu_box(1, game_menu_gen());
} else if (!strcmp(a, "/lang--")) {
do {

View file

@ -125,8 +125,13 @@ function list_check(self, name) -- force using of objects, instead refs
end
function list_add(self, name, pos)
local nam
nam = ref(name);
local nam = name
if stead.initialized then
nam = ref(name);
end
if not nam then
error ("Add wrong object to list: "..tostring(name), 2);
end
if self:look(nam) then
return nil
end
@ -144,12 +149,17 @@ function list_add(self, name, pos)
end
function list_set(self, name, pos)
local nam
local nam = name
local i = tonumber(pos);
if not i then
return nil
end
nam = ref(name);
if stead.initialized then
nam = ref(name);
end
if not nam then
error ("Set wrong object in list: "..tostring(name), 2);
end
if isObject(deref(nam)) then
nam._dynamic_type = true
end

View file

@ -26,9 +26,7 @@ stead.restore_snapshot = function (nr)
if not ss[nr] then return nil, true end -- nothing todo
local i,v
stead:init();
-- game.lifes:zap();
gamefile("main.lua", true);
stead.gamefile("main.lua", true);
local f, err = loadstring(ss[nr]);
if not f then return end

View file

@ -1434,6 +1434,7 @@ function do_ini(self, load)
if not self.showlast then
self._lastdisp = nil;
end
stead.initialized = true
return stead.par('',v, self._lastdisp); --stead.par('^^',v);
end
@ -1637,6 +1638,10 @@ end
function gamefile(file, forget)
if forget then
game._scripts = { }
game.lifes:zap()
game.scriptsforget = true
-- anything else?
stead:init();
end
dofile(file);
game:ini();
@ -1645,8 +1650,13 @@ function gamefile(file, forget)
stead.table.insert(game._scripts, file);
end
end
if forget then
return goto(here());
end
end
stead.gamefile = gamefile
function do_savegame(s, h)
local function save_object(key, value, h)
savevar(h, value, key, false);
@ -1655,10 +1665,12 @@ function do_savegame(s, h)
local function save_var(key, value, h)
savevar(h, value, key, isForSave(key, value, _G))
end
local forget = game.scriptsforget
local i,v
for i,v in ipairs(s._scripts) do
h:write(stead.string.format("gamefile(%q)\n",
v))
h:write(stead.string.format("stead.gamefile(%q,%s)\n",
v, tostring(forget)))
forget = nil
end
save_object('allocator', allocator, h); -- always first!
for_each_object(save_object, h);
@ -2631,6 +2643,7 @@ stead.objects = function(s)
end
stead.init = function(s)
stead.initialized = false
stead:objects();
s.functions = {} -- code blocks
local k,v