aboutsummaryrefslogtreecommitdiff
path: root/src/script/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/graphics')
-rw-r--r--src/script/graphics/luaopen_Canvas.cpp9
-rw-r--r--src/script/graphics/luaopen_Image.cpp9
-rw-r--r--src/script/graphics/luaopen_JSL.cpp19
-rw-r--r--src/script/graphics/luaopen_graphics.cpp43
4 files changed, 50 insertions, 30 deletions
diff --git a/src/script/graphics/luaopen_Canvas.cpp b/src/script/graphics/luaopen_Canvas.cpp
index f869882..a34e3b3 100644
--- a/src/script/graphics/luaopen_Canvas.cpp
+++ b/src/script/graphics/luaopen_Canvas.cpp
@@ -11,7 +11,10 @@ namespace lua
static inline Canvas* checkCanvas(lua_State* L)
{
- return (Canvas*)luax_checktype(L, 1, TYPE_CANVAS);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_CANVAS);
+ if (proxy != nullptr)
+ return (Canvas*)proxy->object;
+ return nullptr;
}
static int l_getWidth(lua_State* L)
@@ -47,7 +50,9 @@ namespace lua
static int l_gc(lua_State* L)
{
-
+ Canvas* canvas = checkCanvas(L);
+ if (canvas != nullptr)
+ delete canvas;
return 0;
}
diff --git a/src/script/graphics/luaopen_Image.cpp b/src/script/graphics/luaopen_Image.cpp
index 7b9b96a..9506ce4 100644
--- a/src/script/graphics/luaopen_Image.cpp
+++ b/src/script/graphics/luaopen_Image.cpp
@@ -11,7 +11,10 @@ namespace lua
static inline Image* checkImage(lua_State* L)
{
- return (Image*)luax_checktype(L, 1, TYPE_IMAGE);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_IMAGE);
+ if (proxy != 0 && proxy != nullptr)
+ return (Image*)proxy->object;
+ return nullptr;
}
static int l_getWidth(lua_State* L)
@@ -60,7 +63,9 @@ namespace lua
static int l_gc(lua_State* L)
{
-
+ Image* i = checkImage(L);
+ if (i != nullptr)
+ delete i;
return 0;
}
diff --git a/src/script/graphics/luaopen_JSL.cpp b/src/script/graphics/luaopen_JSL.cpp
index b5ba125..33afa2c 100644
--- a/src/script/graphics/luaopen_JSL.cpp
+++ b/src/script/graphics/luaopen_JSL.cpp
@@ -11,7 +11,10 @@ namespace lua
static inline JSLProgram* checkJSLProgram(lua_State* L)
{
- return (JSLProgram*)luax_checktype(L, 1, TYPE_JSL);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_JSL);
+ if(proxy != nullptr)
+ return (JSLProgram*)proxy->object;
+ return nullptr;
}
static enum VARIABLE_TYPE
@@ -63,13 +66,15 @@ namespace lua
}
case IMAGE:
{
- Image* img = (Image*)luax_checktype(L, 4, TYPE_IMAGE);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 4, TYPE_IMAGE);
+ Image* img = (Image*)proxy->object;
jsl->sendImage(variable, img);
break;
}
case CANVAS:
{
- Canvas* canvas = (Canvas*)luax_checktype(L, 4, TYPE_IMAGE);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 4, TYPE_IMAGE);
+ Canvas* canvas = (Canvas*)proxy->object;
jsl->sendCanvas(variable, canvas);
break;
}
@@ -116,13 +121,17 @@ namespace lua
static int l_gc(lua_State* L)
{
-
+ JSLProgram* jsl = checkJSLProgram(L);
+ if (jsl != nullptr && jsl != NULL)
+ {
+ delete jsl;
+ }
return 0;
}
static const luaL_Reg f[] = {
+ {"__gc", l_gc },
{"send", l_send},
- {"__gc", l_gc},
{0, 0}
};
diff --git a/src/script/graphics/luaopen_graphics.cpp b/src/script/graphics/luaopen_graphics.cpp
index 80acc94..0d240fe 100644
--- a/src/script/graphics/luaopen_graphics.cpp
+++ b/src/script/graphics/luaopen_graphics.cpp
@@ -76,9 +76,6 @@ namespace lua
*/
static int l_newImage(lua_State* L)
{
- Image* img = (Image*)luax_newinstance(L, TYPE_IMAGE, sizeof(Image));
- // pseudo constructor
- img->init();
Filesystem* fs = Filesystem::get();
const char* f = luax_checkstring(L, 1);
if (!fs->exists(f))
@@ -87,8 +84,11 @@ namespace lua
exit(1);
}
Buffer b;
- fs->read(f, &b);
- img->loadb((const char*)b.data, b.size);
+ fs->read(f, &b);
+
+ Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_IMAGE, sizeof(Proxy));
+ Image* img = new Image((const char*)b.data, b.size);
+ proxy->bind(img);
return 1;
}
@@ -98,10 +98,10 @@ namespace lua
*/
static int l_newShader(lua_State* L)
{
- JSLProgram* j = (JSLProgram*)luax_newinstance(L, TYPE_JSL, sizeof(JSLProgram));
- const char* modestr = luax_checkstring(L, 1);
- j->init(modestr);
-
+ Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_JSL, sizeof(JSLProgram));
+ const char* program = luax_checkstring(L, 1);
+ JSLProgram* jsl = new JSLProgram(program);
+ proxy->bind(jsl);
return 1;
}
@@ -111,10 +111,11 @@ namespace lua
*/
static int l_newCanvas(lua_State* L)
{
- Canvas* cvs = (Canvas*)luax_newinstance(L, TYPE_CANVAS, sizeof(Canvas));
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- cvs->init(w, h);
+ Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_CANVAS, sizeof(Proxy));
+ Canvas* cvs = new Canvas(w, h);
+ proxy->bind(cvs);
return 1;
}
@@ -155,14 +156,14 @@ namespace lua
float r = luax_optnumber(L, 6, 0);
if (luax_istype(L, 1, TYPE_IMAGE))
{
- /* is image */
- Image* p = (Image*)luax_toudata(L, 1);
- p->draw(x, y, sx, sy, r);
+ Proxy* proxy = (Proxy*)luax_toudata(L, 1);
+ Image* img = (Image*)proxy->object;
+ img->draw(x, y, sx, sy, r);
}
else if (luax_istype(L, 1, TYPE_CANVAS))
{
- /* is canvas */
- Canvas* p = (Canvas*)luax_toudata(L, 1);
+ Proxy* proxy = (Proxy*)luax_toudata(L, 1);
+ Canvas* p = (Canvas*)proxy->object;
p->draw(x, y, sx, sy, r);
}
else
@@ -212,7 +213,8 @@ namespace lua
Canvas::unbind();
return 0;
}
- Canvas* c = (Canvas*)luax_checktype(L, 1, TYPE_CANVAS);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_CANVAS);
+ Canvas* c = (Canvas*)proxy->object;
c->bind();
return 0;
}
@@ -232,13 +234,12 @@ namespace lua
}
if (luax_istype(L, 1, TYPE_JSL))
{
- /* is image */
- JSLProgram* jsl = (JSLProgram*)luax_toudata(L, 1);
- jsl->use();
+ Proxy* proxy = (Proxy*)luax_toudata(L, 1);
+ JSLProgram* jsl = (JSLProgram*)proxy->object;
+ jsl->use();
}
else
{
- /* wrong type */
luax_typerror(L, 1, "JSL shader");
}
return 0;