broken stack in lua
This commit is contained in:
parent
9297fbc3d5
commit
f37c6646eb
|
@ -16,24 +16,33 @@ extern char *fromgame(char *s);
|
||||||
char *getstring(char *cmd)
|
char *getstring(char *cmd)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
int N;
|
||||||
if (luaL_dostring(L, cmd)) {
|
if (luaL_dostring(L, cmd)) {
|
||||||
fprintf(stderr,"Error: %s\n", lua_tostring(L, -1));
|
fprintf(stderr,"Error: %s\n", lua_tostring(L, -1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
s = (char*)lua_tostring(L, -1);
|
N = lua_gettop(L);
|
||||||
|
if (N <= 0)
|
||||||
|
return NULL;
|
||||||
|
s = (char*)lua_tostring(L, -N);
|
||||||
if (s)
|
if (s)
|
||||||
s = fromgame(s);
|
s = fromgame(s);
|
||||||
|
lua_pop(L, N);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int luacall(char *cmd)
|
int luacall(char *cmd)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc, N;
|
||||||
if (luaL_dostring(L, cmd)) {
|
if (luaL_dostring(L, cmd)) {
|
||||||
fprintf(stderr,"Error: %s\n", lua_tostring(L, -1));
|
fprintf(stderr,"Error: %s\n", lua_tostring(L, -1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
N = lua_gettop(L);
|
||||||
|
if (N <= 0)
|
||||||
|
return 0;
|
||||||
rc = lua_tonumber(L, -1);
|
rc = lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, N);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ int game_select(const char *name)
|
||||||
return -1;
|
return -1;
|
||||||
if (instead_load(MAIN_FILE))
|
if (instead_load(MAIN_FILE))
|
||||||
return -1;
|
return -1;
|
||||||
instead_eval("game:ini()");
|
instead_eval("game:ini()"); instead_clear();
|
||||||
curgame_dir = games[i].dir;
|
curgame_dir = games[i].dir;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -309,6 +309,11 @@ int game_save(int nr)
|
||||||
p = instead_cmd(cmd);
|
p = instead_cmd(cmd);
|
||||||
if (p)
|
if (p)
|
||||||
free(p);
|
free(p);
|
||||||
|
if (!instead_bretval(1)) {
|
||||||
|
instead_clear();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
instead_clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -991,7 +996,8 @@ static void dec_music(void *data)
|
||||||
if (!curgame_dir)
|
if (!curgame_dir)
|
||||||
return;
|
return;
|
||||||
instead_eval("return dec_music_loop()");
|
instead_eval("return dec_music_loop()");
|
||||||
mus = instead_retval(1);
|
mus = instead_retval(0);
|
||||||
|
instead_clear();
|
||||||
if (!mus)
|
if (!mus)
|
||||||
return;
|
return;
|
||||||
if (atoi(mus) == -1)
|
if (atoi(mus) == -1)
|
||||||
|
@ -1021,9 +1027,10 @@ void game_music_player(void)
|
||||||
} else
|
} else
|
||||||
loop = -1;
|
loop = -1;
|
||||||
|
|
||||||
mus = instead_retval(2);
|
mus = instead_retval(0);
|
||||||
unix_path(mus);
|
unix_path(mus);
|
||||||
|
instead_clear();
|
||||||
|
|
||||||
if (mus && loop == -1) { /* disabled, 0 - forever, 1-n - loops */
|
if (mus && loop == -1) { /* disabled, 0 - forever, 1-n - loops */
|
||||||
free(mus);
|
free(mus);
|
||||||
mus = NULL;
|
mus = NULL;
|
||||||
|
@ -1107,19 +1114,21 @@ void game_sound_player(void)
|
||||||
return;
|
return;
|
||||||
instead_eval("return get_sound()");
|
instead_eval("return get_sound()");
|
||||||
|
|
||||||
snd = instead_retval(1);
|
snd = instead_retval(2);
|
||||||
if (snd) {
|
if (snd) {
|
||||||
loop = atoi(snd);
|
loop = atoi(snd);
|
||||||
free(snd);
|
free(snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
snd = instead_retval(2);
|
snd = instead_retval(1);
|
||||||
if (snd) {
|
if (snd) {
|
||||||
chan = atoi(snd);
|
chan = atoi(snd);
|
||||||
free(snd);
|
free(snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
snd = instead_retval(3);
|
snd = instead_retval(0);
|
||||||
|
instead_clear();
|
||||||
|
|
||||||
if (!snd) {
|
if (!snd) {
|
||||||
if (chan != -1) {
|
if (chan != -1) {
|
||||||
/* halt channel */
|
/* halt channel */
|
||||||
|
@ -1127,7 +1136,7 @@ void game_sound_player(void)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instead_eval("set_sound(nil, -1)");
|
instead_eval("set_sound(nil, -1)"); instead_clear();
|
||||||
|
|
||||||
unix_path(snd);
|
unix_path(snd);
|
||||||
w = sound_find(snd);
|
w = sound_find(snd);
|
||||||
|
@ -1189,7 +1198,7 @@ int game_cmd(char *cmd)
|
||||||
char *pict = NULL;
|
char *pict = NULL;
|
||||||
img_t oldscreen = NULL;
|
img_t oldscreen = NULL;
|
||||||
|
|
||||||
cmdstr = instead_cmd(cmd);
|
cmdstr = instead_cmd(cmd); instead_clear();
|
||||||
// goto err;
|
// goto err;
|
||||||
game_music_player();
|
game_music_player();
|
||||||
game_sound_player();
|
game_sound_player();
|
||||||
|
@ -1197,8 +1206,10 @@ int game_cmd(char *cmd)
|
||||||
if (!cmdstr)
|
if (!cmdstr)
|
||||||
goto inv; /* hackish? ok, yes it is... */
|
goto inv; /* hackish? ok, yes it is... */
|
||||||
|
|
||||||
instead_eval("return get_title();");
|
instead_eval("return get_title();");
|
||||||
title = instead_retval(1);
|
title = instead_retval(0);
|
||||||
|
instead_clear();
|
||||||
|
|
||||||
if (title) {
|
if (title) {
|
||||||
snprintf(buf, sizeof(buf), "<b><c><a:look>%s</a></c></b>", title);
|
snprintf(buf, sizeof(buf), "<b><c><a:look>%s</a></c></b>", title);
|
||||||
txt_layout_set(el_layout(el_title), buf);
|
txt_layout_set(el_layout(el_title), buf);
|
||||||
|
@ -1211,7 +1222,9 @@ int game_cmd(char *cmd)
|
||||||
title_h += game_theme.font_size / 2; // todo?
|
title_h += game_theme.font_size / 2; // todo?
|
||||||
|
|
||||||
instead_eval("return get_picture();");
|
instead_eval("return get_picture();");
|
||||||
pict = instead_retval(1);
|
pict = instead_retval(0);
|
||||||
|
instead_clear();
|
||||||
|
|
||||||
unix_path(pict);
|
unix_path(pict);
|
||||||
|
|
||||||
new_pict = check_new_pict(pict);
|
new_pict = check_new_pict(pict);
|
||||||
|
@ -1252,7 +1265,7 @@ int game_cmd(char *cmd)
|
||||||
el(el_spic)->p.p = NULL;
|
el(el_spic)->p.p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
waystr = instead_cmd("way");
|
waystr = instead_cmd("way"); instead_clear();
|
||||||
|
|
||||||
if (waystr) {
|
if (waystr) {
|
||||||
waystr[strcspn(waystr,"\n")] = 0;
|
waystr[strcspn(waystr,"\n")] = 0;
|
||||||
|
@ -1330,7 +1343,7 @@ int game_cmd(char *cmd)
|
||||||
el_draw(el_scene);
|
el_draw(el_scene);
|
||||||
|
|
||||||
inv:
|
inv:
|
||||||
invstr = instead_cmd("inv");
|
invstr = instead_cmd("inv"); instead_clear();
|
||||||
|
|
||||||
if (invstr && game_theme.inv_mode == INV_MODE_HORIZ) {
|
if (invstr && game_theme.inv_mode == INV_MODE_HORIZ) {
|
||||||
invstr = horiz_inv(invstr);
|
invstr = horiz_inv(invstr);
|
||||||
|
|
|
@ -75,11 +75,15 @@ static int dostring (lua_State *L, const char *s) {
|
||||||
char *getstring(char *cmd)
|
char *getstring(char *cmd)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
int N;
|
||||||
if (!L)
|
if (!L)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (dostring(L, cmd))
|
if (dostring(L, cmd))
|
||||||
return NULL;
|
return NULL;
|
||||||
s = (char*)lua_tostring(L, -1);
|
N = lua_gettop(L); /* number of arguments */
|
||||||
|
if (N <=0)
|
||||||
|
return NULL;
|
||||||
|
s = (char*)lua_tostring(L, -N);
|
||||||
if (s)
|
if (s)
|
||||||
s = fromgame(s);
|
s = fromgame(s);
|
||||||
return s;
|
return s;
|
||||||
|
@ -95,15 +99,42 @@ int instead_eval(char *s)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int instead_clear(void)
|
||||||
|
{
|
||||||
|
int N;
|
||||||
|
if (!L)
|
||||||
|
return -1;
|
||||||
|
N = lua_gettop(L); /* number of arguments */
|
||||||
|
lua_pop(L, N);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *instead_retval(int n)
|
char *instead_retval(int n)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
s = (char*)lua_tostring(L, -n);
|
int N;
|
||||||
|
if (!L)
|
||||||
|
return NULL;
|
||||||
|
N = lua_gettop(L); /* number of arguments */
|
||||||
|
if (n - N >= 0)
|
||||||
|
return NULL;
|
||||||
|
s = (char*)lua_tostring(L, n - N);
|
||||||
if (s)
|
if (s)
|
||||||
s = fromgame(s);
|
s = fromgame(s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int instead_bretval(int n)
|
||||||
|
{
|
||||||
|
int N;
|
||||||
|
if (!L)
|
||||||
|
return 0;
|
||||||
|
N = lua_gettop(L); /* number of arguments */
|
||||||
|
if (n - N >= 0)
|
||||||
|
return 1;
|
||||||
|
return lua_toboolean(L, n - N);
|
||||||
|
}
|
||||||
|
|
||||||
char *instead_cmd(char *s)
|
char *instead_cmd(char *s)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
@ -231,6 +262,7 @@ int instead_load(char *game)
|
||||||
if (fromcp)
|
if (fromcp)
|
||||||
free(fromcp);
|
free(fromcp);
|
||||||
fromcp = getstring("return game.codepage;");
|
fromcp = getstring("return game.codepage;");
|
||||||
|
instead_clear();
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ extern int instead_load(char *game);
|
||||||
extern void instead_done(void);
|
extern void instead_done(void);
|
||||||
extern char *instead_cmd(char *s);
|
extern char *instead_cmd(char *s);
|
||||||
extern int instead_eval(char *s);
|
extern int instead_eval(char *s);
|
||||||
|
extern int instead_clear(void);
|
||||||
extern char *instead_retval(int n);
|
extern char *instead_retval(int n);
|
||||||
|
extern int instead_bretval(int n);
|
||||||
char *fromgame(const char *s);
|
char *fromgame(const char *s);
|
||||||
extern int instead_encode(const char *s, const char *d);
|
extern int instead_encode(const char *s, const char *d);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1633,7 +1633,7 @@ iface = {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if v == false then
|
if v == false then
|
||||||
return fmt(ACTION_TEXT);
|
return fmt(ACTION_TEXT), false;
|
||||||
end
|
end
|
||||||
vv = fmt(cat(par("^^",l,ACTION_TEXT,vv),'^'));
|
vv = fmt(cat(par("^^",l,ACTION_TEXT,vv),'^'));
|
||||||
if st then
|
if st then
|
||||||
|
|
Reference in a new issue