diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/audio/luaopen_Sound.cpp | 1 | ||||
-rw-r--r-- | src/script/audio/luaopen_audio.cpp | 5 | ||||
-rw-r--r-- | src/script/graphics/luaopen_Canvas.cpp | 9 | ||||
-rw-r--r-- | src/script/graphics/luaopen_Image.cpp | 9 | ||||
-rw-r--r-- | src/script/graphics/luaopen_JSL.cpp | 19 | ||||
-rw-r--r-- | src/script/graphics/luaopen_graphics.cpp | 43 | ||||
-rw-r--r-- | src/script/joypad/joypad.h | 14 | ||||
-rw-r--r-- | src/script/joypad/luaopen_joypad.cpp | 21 | ||||
-rw-r--r-- | src/script/luaopen_jin.cpp | 4 | ||||
-rw-r--r-- | src/script/luaopen_types.h | 12 |
10 files changed, 104 insertions, 33 deletions
diff --git a/src/script/audio/luaopen_Sound.cpp b/src/script/audio/luaopen_Sound.cpp index f2767bd..d43147e 100644 --- a/src/script/audio/luaopen_Sound.cpp +++ b/src/script/audio/luaopen_Sound.cpp @@ -21,5 +21,6 @@ namespace lua return 1; } + } } diff --git a/src/script/audio/luaopen_audio.cpp b/src/script/audio/luaopen_audio.cpp index f170115..78d7a69 100644 --- a/src/script/audio/luaopen_audio.cpp +++ b/src/script/audio/luaopen_audio.cpp @@ -22,7 +22,7 @@ namespace lua return 0; } - + static const luaL_Reg f[] = { {"init", l_init}, {"Sound", l_newSound}, @@ -31,7 +31,8 @@ namespace lua int luaopen_audio(lua_State* L) { - + luax_newlib(L, f); + return 1; } } 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; diff --git a/src/script/joypad/joypad.h b/src/script/joypad/joypad.h new file mode 100644 index 0000000..e8d309b --- /dev/null +++ b/src/script/joypad/joypad.h @@ -0,0 +1,14 @@ +#ifndef __JIN_JOYPAD_H +#define __JIN_JOYPAD_H + +namespace jin +{ +namespace input +{ + + + +} +} + +#endif
\ No newline at end of file diff --git a/src/script/joypad/luaopen_joypad.cpp b/src/script/joypad/luaopen_joypad.cpp new file mode 100644 index 0000000..0166a57 --- /dev/null +++ b/src/script/joypad/luaopen_joypad.cpp @@ -0,0 +1,21 @@ +#include "libjin/jin.h" +#include "3rdparty/luax/luax.h" + +namespace jin +{ +namespace lua +{ + + static const luaL_Reg f[] = { + { 0, 0 } + }; + + int luaopen_joypad(lua_State* L) + { + luax_newlib(L, f); + + return 1; + } + +} +}
\ No newline at end of file diff --git a/src/script/luaopen_jin.cpp b/src/script/luaopen_jin.cpp index d7262e1..dcf8830 100644 --- a/src/script/luaopen_jin.cpp +++ b/src/script/luaopen_jin.cpp @@ -18,6 +18,7 @@ namespace lua extern int luaopen_mouse(lua_State* L); extern int luaopen_keyboard(lua_State* L); extern int luaopen_filesystem(lua_State* L); + extern int luaopen_joypad(lua_State* L); static int l_getversion(lua_State* L) { @@ -60,7 +61,8 @@ namespace lua {"keyboard", luaopen_keyboard}, {"filesystem", luaopen_filesystem}, {"net", luaopen_net}, - //{"audio", luaopen_audio}, + {"audio", luaopen_audio}, + {"joypad", luaopen_joypad}, {0, 0} }; diff --git a/src/script/luaopen_types.h b/src/script/luaopen_types.h index 292d991..8c1f2a6 100644 --- a/src/script/luaopen_types.h +++ b/src/script/luaopen_types.h @@ -10,4 +10,16 @@ // audio module #define TYPE_SOUND "Sound" +class Proxy +{ +public: + inline void bind(void* obj) + { + if (obj != 0 && obj != nullptr) + object = obj; + } + + void* object; +}; + #endif |