aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/graphics/bitmap.cpp26
-rw-r--r--src/lua/modules/graphics/graphics.cpp15
-rw-r--r--src/lua/modules/mouse/mouse.cpp3
3 files changed, 37 insertions, 7 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
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index 573392d..8a58ff0 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -86,6 +86,21 @@ namespace lua
int h = luax_checkinteger(L, 2);
bitmap = Bitmap::createBitmap(w, h);
}
+ else if (luax_gettop(L) == 3)
+ {
+ int w = luax_checkinteger(L, 1);
+ int h = luax_checkinteger(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
+ }
else
{
const char* f = luax_checkstring(L, 1);
diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/mouse.cpp
index a43c275..390936c 100644
--- a/src/lua/modules/mouse/mouse.cpp
+++ b/src/lua/modules/mouse/mouse.cpp
@@ -21,7 +21,8 @@ namespace lua
static int l_setVisible(lua_State* L)
{
bool visible = luax_checkbool(L, 1);
- SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
+ Mouse* mouse = Mouse::get();
+ mouse->setVisible(visible);
return 0;
}