From 9458eb868631b29e00182c37f1c7e46981b68edd Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 18 May 2018 15:27:59 +0800 Subject: GC --- src/script/audio/luaopen_Sound.cpp | 26 -------------------------- src/script/audio/luaopen_Source.cpp | 26 ++++++++++++++++++++++++++ src/script/graphics/luaopen_Canvas.cpp | 6 +++--- src/script/graphics/luaopen_Image.cpp | 6 +++--- src/script/graphics/luaopen_JSL.cpp | 8 +++----- src/script/luaopen_types.h | 6 +++++- 6 files changed, 40 insertions(+), 38 deletions(-) delete mode 100644 src/script/audio/luaopen_Sound.cpp create mode 100644 src/script/audio/luaopen_Source.cpp (limited to 'src/script') diff --git a/src/script/audio/luaopen_Sound.cpp b/src/script/audio/luaopen_Sound.cpp deleted file mode 100644 index d43147e..0000000 --- a/src/script/audio/luaopen_Sound.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "3rdparty/luax/luax.h" - -namespace jin -{ -namespace lua -{ - - static int l_play(lua_State* L) - { - - return 0; - } - - static const luaL_Reg f[] = { - {"play", l_play}, - {0, 0} - }; - - int luaopen_Sound(lua_State* L) - { - - return 1; - } - -} -} diff --git a/src/script/audio/luaopen_Source.cpp b/src/script/audio/luaopen_Source.cpp new file mode 100644 index 0000000..2ab5d16 --- /dev/null +++ b/src/script/audio/luaopen_Source.cpp @@ -0,0 +1,26 @@ +#include "3rdparty/luax/luax.h" + +namespace jin +{ +namespace lua +{ + + static int l_play(lua_State* L) + { + + return 0; + } + + static const luaL_Reg f[] = { + {"play", l_play}, + {0, 0} + }; + + int luaopen_Source(lua_State* L) + { + + return 1; + } + +} +} diff --git a/src/script/graphics/luaopen_Canvas.cpp b/src/script/graphics/luaopen_Canvas.cpp index a34e3b3..1e22772 100644 --- a/src/script/graphics/luaopen_Canvas.cpp +++ b/src/script/graphics/luaopen_Canvas.cpp @@ -50,9 +50,9 @@ namespace lua static int l_gc(lua_State* L) { - Canvas* canvas = checkCanvas(L); - if (canvas != nullptr) - delete canvas; + Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_CANVAS); + Canvas* canvas = (Canvas*)proxy->object; + delete canvas; return 0; } diff --git a/src/script/graphics/luaopen_Image.cpp b/src/script/graphics/luaopen_Image.cpp index 9506ce4..246ea09 100644 --- a/src/script/graphics/luaopen_Image.cpp +++ b/src/script/graphics/luaopen_Image.cpp @@ -63,9 +63,9 @@ namespace lua static int l_gc(lua_State* L) { - Image* i = checkImage(L); - if (i != nullptr) - delete i; + Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_IMAGE); + Image* img = (Image*)proxy->object; + delete img; return 0; } diff --git a/src/script/graphics/luaopen_JSL.cpp b/src/script/graphics/luaopen_JSL.cpp index 33afa2c..919949c 100644 --- a/src/script/graphics/luaopen_JSL.cpp +++ b/src/script/graphics/luaopen_JSL.cpp @@ -121,11 +121,9 @@ namespace lua static int l_gc(lua_State* L) { - JSLProgram* jsl = checkJSLProgram(L); - if (jsl != nullptr && jsl != NULL) - { - delete jsl; - } + Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_JSL); + JSLProgram* jsl = (JSLProgram*)proxy->object; + delete jsl; return 0; } diff --git a/src/script/luaopen_types.h b/src/script/luaopen_types.h index 8c1f2a6..c6ce202 100644 --- a/src/script/luaopen_types.h +++ b/src/script/luaopen_types.h @@ -8,7 +8,7 @@ #define TYPE_FONT "Font" // audio module -#define TYPE_SOUND "Sound" +#define TYPE_SOURCE "Source" class Proxy { @@ -20,6 +20,10 @@ public: } void* object; + + ~Proxy() + { + } }; #endif -- cgit v1.1-26-g67d0