diff options
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/embed/boot.lua.h | 20 | ||||
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 33 |
2 files changed, 26 insertions, 27 deletions
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h index f41ba3b..055a653 100644 --- a/src/lua/embed/boot.lua.h +++ b/src/lua/embed/boot.lua.h @@ -138,27 +138,29 @@ jin.nogame = { ------------------------------------------------------------------------- local function onError(msg) - local tab = ' ' print("Error:\n" .. msg) function jin.core.onEvent(e) - if e.type == 'quit' then + if e.type == "Quit" then jin.core.stop() end end - local ww, wh = jin.graphics.getSize() function jin.core.onDraw() - jin.graphics.write("Error: ", 10, 10, 30, 3, 30) - jin.graphics.write(msg, 10, 50) + jin.graphics.unsetFont() + jin.graphics.print("Error:\n" .. msg .. "\n" .. debug.traceback(), 5, 5) end + jin.graphics.setClearColor(100, 100, 100, 255) + jin.core.onLoad = nil + jin.core.run() + jin.core.quit() end local function boot() if jin.filesystem.exist("main.lua") then - -- require main game script + -- Require main game script xpcall(function() require"main" end, onError) - jin.core.run() + xpcall(function() jin.core.run() end, onError) else - -- no game + -- No game jin.core.setHandler(jin.nogame) jin.core.run() end @@ -169,4 +171,4 @@ end xpcall(boot, onError) -)"; +)";
\ No newline at end of file diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 4ff0dfc..5ba8c13 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -125,25 +125,13 @@ namespace JinEngine error(L, "No such image file %s", f); goto fail; } - Buffer b = {}; + Buffer b; if (!fs->read(f, b)) { error(L, "Failed to read image %s", f); goto fail; } bitmap = Bitmap::createBitmap(&b, b.size()); - //const Color* col = bitmap->getPixels(); - //ofstream o = ofstream("img.txt", ios_base::app); - //for (int i = 0; i < bitmap->getWidth() * bitmap->getHeight(); ++i) - //{ - // Color c = col[i]; - // o << (int)c.r << ','; - // o << (int)c.g << ','; - // o << (int)c.b << ','; - // o << (int)c.a << ','; - // if ((i + 1) % 10 == 0) - // o << endl; - //} if (bitmap == nullptr) { error(L, "Failed to decode image file %s", f); @@ -161,12 +149,21 @@ namespace JinEngine /* jin.graphics.newTexture(bitmap) */ static int l_newTexture(lua_State* L) { - Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP); - Ref<Bitmap>& refBitmap = p->getRef<Bitmap>(); - Bitmap* bitmap = refBitmap.getObject(); + Texture* texture = nullptr; + if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP)) + { + Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP); + Ref<Bitmap>& refBitmap = p->getRef<Bitmap>(); + Bitmap* bitmap = refBitmap.getObject(); + texture = Texture::createTexture(bitmap); + } + else if (luax_isstring(L, 1)) + { + const char* path = luax_checkstring(L, 1); + texture = Texture::createTexture(path); + } Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy)); - Texture* tex = Texture::createTexture(bitmap); - proxy->bind(new Ref<Texture>(tex, JIN_GRAPHICS_TEXTURE)); + proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE)); return 1; } |