aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp18
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp20
2 files changed, 19 insertions, 19 deletions
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
index 0f2f713..698d88a 100644
--- a/src/lua/modules/audio/je_lua_audio.cpp
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -78,28 +78,28 @@ namespace JinEngine
AssetDatabase* fs = AssetDatabase::get();
const char* f = luax_checkstring(L, 1);
Buffer b;
- if (!fs->exists(f))
+ try
{
- error(L, "No such image %s", f);
- goto fail;
+ if (!fs->exists(f))
+ throw Exception("No such source file %s.", f);
+ fs->read(f, b);
}
- if (!fs->read(f, b))
+ catch (Exception& e)
{
error(L, "Failed to read source file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
Source* src = Source::createSource((void*)&b, b.size());
if (src == nullptr)
{
error(L, "Failed to decode source file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
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;
}
LUA_IMPLEMENT int l_destroy(lua_State* L)
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 6324e00..7efb2e7 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -128,30 +128,30 @@ namespace JinEngine
{
const char* f = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
- if (!fs->exists(f))
+ Buffer b;
+ try
{
- error(L, "No such image file %s", f);
- goto fail;
+ if (!fs->exists(f))
+ throw Exception("No such image file %s.", f);
+ fs->read(f, b);
}
- Buffer b;
- if (!fs->read(f, b))
+ catch (Exception& e)
{
error(L, "Failed to read image %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
bitmap = Bitmap::createBitmap(&b, b.size());
if (bitmap == nullptr)
{
error(L, "Failed to decode image file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
- fail:
- luax_pushnil(L);
- return 1;
}
/* jin.graphics.newTexture(bitmap) */