From 074f9fe1ac195284865ac7b123469bafe2c9679f Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 6 Sep 2018 21:30:06 +0800 Subject: *update --- src/lua/modules/graphics/graphics.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/lua/modules') diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 909e70c..573392d 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -79,17 +79,27 @@ namespace lua static int l_newBitmap(lua_State* L) { - Filesystem* fs = Filesystem::get(); - const char* f = luax_checkstring(L, 1); - if (!fs->exists(f)) + Bitmap* bitmap = nullptr; + if (luax_gettop(L) == 2) { - printf("Error: no such texture %s\n", f); - exit(1); + int w = luax_checkinteger(L, 1); + int h = luax_checkinteger(L, 2); + bitmap = Bitmap::createBitmap(w, h); + } + else + { + const char* f = luax_checkstring(L, 1); + Filesystem* fs = Filesystem::get(); + if (!fs->exists(f)) + { + printf("Error: no such texture %s\n", f); + exit(1); + } + Buffer b; + fs->read(f, &b); + bitmap = Bitmap::createBitmap(b.data, b.size); } - Buffer b; - fs->read(f, &b); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy)); - Bitmap* bitmap = Bitmap::createBitmap(b.data, b.size); proxy->bind(new Ref(bitmap, JIN_GRAPHICS_BITMAP)); return 1; } -- cgit v1.1-26-g67d0