diff options
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/core/luaopen_core.cpp | 8 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Canvas.cpp | 23 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Image.cpp | 15 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_JSL.cpp | 10 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_graphics.cpp | 3 |
5 files changed, 40 insertions, 19 deletions
diff --git a/src/lua/core/luaopen_core.cpp b/src/lua/core/luaopen_core.cpp index 42de91b..54af3c0 100644 --- a/src/lua/core/luaopen_core.cpp +++ b/src/lua/core/luaopen_core.cpp @@ -1,14 +1,16 @@ #include "libs/luax/luax.h" #include "core/game.h" -using namespace jin::core; + namespace jin { namespace lua { + using namespace jin::core; + static int l_running(lua_State* L) { - bool r = Game::get()->running(); - luax_pushboolean(L, r); + bool running = Game::get()->running(); + luax_pushboolean(L, running); return 1; } diff --git a/src/lua/graphics/luaopen_Canvas.cpp b/src/lua/graphics/luaopen_Canvas.cpp index edcd1ae..88d6e09 100644 --- a/src/lua/graphics/luaopen_Canvas.cpp +++ b/src/lua/graphics/luaopen_Canvas.cpp @@ -1,28 +1,36 @@ #include "libs/luax/luax.h" #include "../luaopen_types.h" #include "render/canvas.h" -using namespace jin::render; + namespace jin { namespace lua { + + using namespace jin::render; + + static inline Canvas* checkCanvas(lua_State* L) + { + return (Canvas*)luax_checktype(L, 1, TYPE_CANVAS); + } + static int l_getWidth(lua_State* L) { - Canvas* c = (Canvas*)luax_checktype(L, 1, TYPE_CANVAS); + Canvas* c = checkCanvas(L); luax_pushnumber(L, c->getWidth()); return 1; } static int l_getHeight(lua_State* L) { - Canvas* c = (Canvas*)luax_checktype(L, 1, TYPE_CANVAS); + Canvas* c = checkCanvas(L); luax_pushnumber(L, c->getHeight()); return 1; } static int l_getSize(lua_State* L) { - Canvas* c = (Canvas*)luax_checktype(L, 1, TYPE_CANVAS); + Canvas* c = checkCanvas(L); luax_pushnumber(L, c->getWidth()); luax_pushnumber(L, c->getHeight()); return 2; @@ -30,7 +38,7 @@ namespace lua static int l_setAnchor(lua_State* L) { - Canvas* c = (Canvas*)luax_checktype(L, 1, TYPE_CANVAS); + Canvas* c = checkCanvas(L); int x = luax_checknumber(L, 1); int y = luax_checknumber(L, 2); c->setAnchor(x, y); @@ -57,5 +65,6 @@ namespace lua luax_newtype(L, TYPE_CANVAS, f); return 0; } -} -}
\ No newline at end of file + +}// lua +}// jin
\ No newline at end of file diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/graphics/luaopen_Image.cpp index 2637db9..b25dcc8 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/graphics/luaopen_Image.cpp @@ -9,23 +9,28 @@ namespace jin namespace lua { + static inline Image* checkImage(lua_State* L) + { + return (Image*)luax_checktype(L, 1, TYPE_IMAGE); + } + static int l_getWidth(lua_State* L) { - Image* i = (Image*)luax_checktype(L, 1, TYPE_IMAGE); + Image* i = checkImage(L); luax_pushnumber(L, i->getWidth()); return 1; } static int l_getHeight(lua_State *L) { - Image* i = (Image*)luax_checktype(L, 1, TYPE_IMAGE); + Image* i = checkImage(L); luax_pushnumber(L, i->getHeight()); return 1; } static int l_getPixel(lua_State* L) { - Image* i = (Image*)luax_checktype(L, 1, TYPE_IMAGE); + Image* i = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); color c = i->getPixel(x, y); @@ -38,7 +43,7 @@ namespace lua static int l_setAnchor(lua_State* L) { - Image* i = (Image*)luax_checktype(L, 1, TYPE_IMAGE); + Image* i = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); i->setAnchor(x, y); @@ -47,7 +52,7 @@ namespace lua static int l_getSize(lua_State* L) { - Image* i = (Image*)luax_checktype(L, 1, TYPE_IMAGE); + Image* i = checkImage(L); luax_pushnumber(L, i->getWidth()); luax_pushnumber(L, i->getHeight()); return 2; diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/graphics/luaopen_JSL.cpp index 19fa285..d1d3bac 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/graphics/luaopen_JSL.cpp @@ -5,9 +5,15 @@ namespace jin { namespace lua { + using namespace render; - enum VARIABLE_TYPE + static inline JSLProgram* checkJSLProgram(lua_State* L) + { + return (JSLProgram*)luax_checktype(L, 1, TYPE_JSL); + } + + static enum VARIABLE_TYPE { INVALID = 0, NUMBER , @@ -29,7 +35,7 @@ namespace lua */ static int l_send(lua_State* L) { - JSLProgram* jsl = (JSLProgram*)luax_checktype(L, 1, TYPE_JSL); + JSLProgram* jsl = checkJSLProgram(L); // number Image Texel const char* typestr = luax_checkstring(L, 2); // variable name diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index 8ddd455..009b1bd 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -1,5 +1,4 @@ -#include <SDL2/SDL.h> - +#include "utils/macros.h" #include "libs/luax/luax.h" #include "render/image.h" |