diff options
Diffstat (limited to 'src/lua/modules/audio/audio.cpp')
-rw-r--r-- | src/lua/modules/audio/audio.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
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<Source>(src, JIN_AUDIO_SOURCE)); return 1; + fail: + luax_pushnil(L); + return 1; } static int l_destroy(lua_State* L) |