From 4798e70dcbbedb55de8e9f8e321e8fad7b9783f6 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 8 Sep 2018 13:09:06 +0800 Subject: *update --- src/lua/modules/audio/audio.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/lua/modules/audio/audio.cpp') diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp index 3d29e17..7590104 100644 --- a/src/lua/modules/audio/audio.cpp +++ b/src/lua/modules/audio/audio.cpp @@ -64,17 +64,29 @@ namespace lua { Filesystem* fs = Filesystem::get(); const char* f = luax_checkstring(L, 1); + Buffer b; if (!fs->exists(f)) { - printf("Error: no such image %s\n", f); - exit(1); + error(L, "No such image %s", f); + goto fail; + } + if (!fs->read(f, &b)) + { + error(L, "Failed to read source file %s", f); + goto fail; } - Buffer b; - fs->read(f, &b); - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy)); Source* src = Source::createSource(b.data, b.size); + if (src == nullptr) + { + error(L, "Failed to decode source file %s", f); + goto fail; + } + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy)); proxy->bind(new Ref(src, JIN_AUDIO_SOURCE)); return 1; + fail: + luax_pushnil(L); + return 1; } static int l_destroy(lua_State* L) -- cgit v1.1-26-g67d0