aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/bitmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/bitmap.cpp')
-rw-r--r--src/lua/modules/graphics/bitmap.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/lua/modules/graphics/bitmap.cpp b/src/lua/modules/graphics/bitmap.cpp
index 81c36f1..6067442 100644
--- a/src/lua/modules/graphics/bitmap.cpp
+++ b/src/lua/modules/graphics/bitmap.cpp
@@ -20,7 +20,6 @@ namespace lua
static int l_gc(lua_State* L)
{
- printf("collect bitmap\n");
BitmapRef ref = checkBitmap(L);
ref.release();
return 0;
@@ -70,14 +69,29 @@ namespace lua
BitmapRef ref = checkBitmap(L);
int x = luax_checkinteger(L, 2);
int y = luax_checkinteger(L, 3);
- unsigned char r = luax_checkinteger(L, 4);
- unsigned char g = luax_checkinteger(L, 5);
- unsigned char b = luax_checkinteger(L, 6);
- unsigned char a = luax_checkinteger(L, 7);
+ if (!luax_istable(L, 4))
+ {
+ luax_typerror(L, 4, "table");
+ return 1;
+ }
+ unsigned int r = luax_rawgetnumber(L, 4, 1);
+ unsigned int g = luax_rawgetnumber(L, 4, 2);
+ unsigned int b = luax_rawgetnumber(L, 4, 3);
+ unsigned int a = luax_rawgetnumber(L, 4, 4);
ref->setPixel(Color(r, g, b, a), x, y);
return 0;
}
+ static int l_clone(lua_State* L)
+ {
+ BitmapRef ref = checkBitmap(L);
+ Bitmap* bitmap = ref.getObject();
+ Bitmap* b = Bitmap::clone(bitmap);
+ Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
+ proxy->bind(new Ref<Bitmap>(b, JIN_GRAPHICS_BITMAP));
+ return 1;
+ }
+
static const luaL_Reg f[] = {
{ "__gc", l_gc },
{ "getWidth", l_getWidth },
@@ -85,6 +99,7 @@ namespace lua
{ "getSize", l_getSize },
{ "getPixel", l_getPixel },
{ "setPixel", l_setPixel },
+ { "clone", l_clone },
{ 0, 0 }
};
@@ -94,6 +109,5 @@ namespace lua
return 0;
}
-
}
} \ No newline at end of file