Skip to content

Commit c466b16

Browse files
author
Peter Kosyh
committed
mmedia @
1 parent 8c5a0ba commit c466b16

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install: all
2424
$(INSTALLD) $(DESTDIR)/$(BIN)
2525
$(INSTALLB) instead-cli$(EXE) $(DESTDIR)/$(BIN)/instead-cli$(EXE)
2626
$(INSTALLD) $(DESTDIR)/$(STEADPATH)
27-
for d in stead2 stead3 stead3/ext; do \
27+
for d in stead2 stead3 stead2/ext stead3/ext; do \
2828
$(INSTALLD) $(DESTDIR)/$(STEADPATH)/$$d; \
2929
$(INSTALL) instead/stead/$$d/*.lua $(DESTDIR)/$(STEADPATH)/$$d/; \
3030
done

instead

main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ static void show_err(void)
211211
}
212212
}
213213

214+
static char *media[] = { NULL, NULL };
215+
static char *media_fn[] = {
216+
"instead.get_picture",
217+
"instead.get_music"
218+
};
219+
220+
static void mmedia(int t)
221+
{
222+
char *mm;
223+
instead_lock();
224+
instead_function(media_fn[t], NULL);
225+
mm = instead_retval(0);
226+
instead_clear();
227+
instead_unlock();
228+
if (!mm && !media[t])
229+
return;
230+
if ((!media[t] && mm) || (media[t] && !mm) ||
231+
strcmp(media[t], mm)) {
232+
free(media[t]);
233+
media[t] = mm;
234+
if (mm && *mm) { /* changed */
235+
printf("@ %s\n", mm);
236+
}
237+
}
238+
}
214239
int main(int argc, const char **argv)
215240
{
216241
int rc, i;
@@ -297,6 +322,7 @@ int main(int argc, const char **argv)
297322
fprintf(stdout, "Can not load game: %s\n", instead_err());
298323
exit(1);
299324
}
325+
mmedia(0); mmedia(1);
300326
if (opt_autoload) {
301327
snprintf(cmd, sizeof(cmd), "load %s", opt_autoload);
302328
printf("%s\n", cmd);
@@ -322,7 +348,6 @@ int main(int argc, const char **argv)
322348
break;
323349
if (!strcmp(p, "/quit"))
324350
break;
325-
326351
rc = 1; str = NULL;
327352

328353
if (*p == '/') {
@@ -356,6 +381,7 @@ int main(int argc, const char **argv)
356381
str = instead_cmd(cmd, &rc);
357382
}
358383
if (str) {
384+
mmedia(0); mmedia(1);
359385
fmt(trim(str), opt_width);
360386
free(str);
361387
}

tiny.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
if API == 'stead3' then
88
require 'tiny3'
9+
require "ext/sound"
910
local instead = std '@instead'
1011
local iface = std '@iface'
12+
instead.music_callback = function() end
1113
instead.restart = instead_restart
1214
instead.menu = instead_menu
1315
instead.savepath = function() return "./" end
16+
1417
function iface:em(str)
1518
if type(str) == 'string' then
1619
return '/'..str..'/'
@@ -21,6 +24,13 @@ if API == 'stead3' then
2124
return '*'..str..'*'
2225
end
2326
end
27+
instead.get_picture = function()
28+
local s = stead.call(std.here(), 'pic')
29+
if not s then
30+
s = stead.call(std.ref 'game', 'pic')
31+
end
32+
return s and std.tostr(s)
33+
end
2434
std.mod_start(function()
2535
std.mod_init(function()
2636
std.rawset(_G, 'instead', instead)
@@ -33,4 +43,5 @@ if API == 'stead3' then
3343
end)
3444
else
3545
require 'tiny2'
46+
require "ext/sound"
3647
end

0 commit comments

Comments
 (0)