From 8585c92b7d0744a1f1a39c872cf5096621161b6c Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 16 Aug 2018 14:21:56 +0800 Subject: *update --- src/lua/graphics/luaopen_Image.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/lua/graphics/luaopen_Image.cpp') diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/graphics/luaopen_Image.cpp index 8d89a80..b1672d5 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/graphics/luaopen_Image.cpp @@ -1,43 +1,42 @@ #include "lua/luax.h" #include "lua/luaopen_types.h" -#include "Image.h" -#include "Color.h" +#include "libjin/jin.h" namespace jin { namespace lua { - using namespace lua::graphics; + using namespace jin::graphics; - static inline Image* checkImage(lua_State* L) + typedef Texture Image; + + static inline Ref& checkImage(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_IMAGE); - if (proxy != nullptr) - return (Image*)proxy->object; - return nullptr; + return proxy->getRef(); } static int l_getWidth(lua_State* L) { - Image* i = checkImage(L); - luax_pushnumber(L, i->getWidth()); + Ref& ref = checkImage(L); + luax_pushnumber(L, (*ref).getWidth()); return 1; } static int l_getHeight(lua_State *L) { - Image* i = checkImage(L); - luax_pushnumber(L, i->getHeight()); + Ref& ref = checkImage(L); + luax_pushnumber(L, (*ref).getHeight()); return 1; } static int l_getPixel(lua_State* L) { - Image* i = checkImage(L); + Ref& ref = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); - color c = i->getPixel(x, y); + color c = (*ref).getPixel(x, y); luax_pushnumber(L, c.rgba.r); luax_pushnumber(L, c.rgba.g); luax_pushnumber(L, c.rgba.b); @@ -47,18 +46,18 @@ namespace lua static int l_setAnchor(lua_State* L) { - Image* i = checkImage(L); + Ref& ref = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); - i->setAnchor(x, y); + (*ref).setAnchor(x, y); return 0; } static int l_getSize(lua_State* L) { - Image* i = checkImage(L); - luax_pushnumber(L, i->getWidth()); - luax_pushnumber(L, i->getHeight()); + Ref& ref = checkImage(L); + luax_pushnumber(L, (*ref).getWidth()); + luax_pushnumber(L, (*ref).getHeight()); return 2; } -- cgit v1.1-26-g67d0