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_JSL.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/lua/graphics/luaopen_JSL.cpp') diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/graphics/luaopen_JSL.cpp index 774f2b6..e644c35 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/graphics/luaopen_JSL.cpp @@ -1,23 +1,20 @@ #include "lua/luax.h" #include "lua/luaopen_types.h" -#include "Image.h" -#include "JSL.h" -#include "Canvas.h" -#include "Color.h" +#include "libjin/jin.h" namespace jin { namespace lua { - using namespace lua::graphics; + using namespace jin::graphics; - static inline JSLProgram* checkJSLProgram(lua_State* L) + typedef Texture Image; + + static inline Ref& checkJSLProgram(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER); - if(proxy != nullptr) - return (JSLProgram*)proxy->object; - return nullptr; + return proxy->getRef(); } static enum VARIABLE_TYPE @@ -51,7 +48,7 @@ namespace lua */ static int l_send(lua_State* L) { - JSLProgram* jsl = checkJSLProgram(L); + Ref& ref = checkJSLProgram(L); // number Image Texel const char* typestr = luax_checkstring(L, 2); // variable name @@ -64,28 +61,28 @@ namespace lua case NUMBER: { float number = luax_checknumber(L, 4); - jsl->sendFloat(variable, number); + (*ref).sendFloat(variable, number); break; } case IMAGE: { Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_IMAGE); - Image* tex = (Image*)proxy->object; - jsl->sendImage(variable, tex); + Ref& tex = proxy->getRef(); + (*ref).sendTexture(variable, &(*tex)); break; } case CANVAS: { Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_CANVAS); - Canvas* canvas = (Canvas*)proxy->object; - jsl->sendCanvas(variable, canvas); + Ref& canvas = proxy->getRef(); + (*ref).sendCanvas(variable, &(*canvas)); break; } case VEC2: { float x = luax_checknumber(L, 4); float y = luax_checknumber(L, 5); - jsl->sendVec2(variable, x, y); + (*ref).sendVec2(variable, x, y); break; } case VEC3: @@ -93,7 +90,7 @@ namespace lua float x = luax_checknumber(L, 4); float y = luax_checknumber(L, 5); float z = luax_checknumber(L, 6); - jsl->sendVec3(variable, x, y, z); + (*ref).sendVec3(variable, x, y, z); break; } case VEC4: @@ -102,7 +99,7 @@ namespace lua float y = luax_checknumber(L, 5); float z = luax_checknumber(L, 6); float w = luax_checknumber(L, 7); - jsl->sendVec4(variable, x, y, z, w); + (*ref).sendVec4(variable, x, y, z, w); break; } case COLOR: @@ -112,7 +109,7 @@ namespace lua col.rgba.g = luax_checkinteger(L, 5); col.rgba.b = luax_checkinteger(L, 6); col.rgba.a = luax_checkinteger(L, 7); - jsl->sendColor(variable, &col); + (*ref).sendColor(variable, &col); break; } default: -- cgit v1.1-26-g67d0