aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-06 21:30:06 +0800
committerchai <chaifix@163.com>2018-09-06 21:30:06 +0800
commit074f9fe1ac195284865ac7b123469bafe2c9679f (patch)
tree0ca739dbf92f706c059c3424d18efe4fac07b30c /src/lua/modules
parent957c073df5fc2c57d531c96cdca11bfafdbae076 (diff)
*update
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/graphics/graphics.cpp26
1 files changed, 18 insertions, 8 deletions
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>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
}