aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/game.cpp15
-rw-r--r--src/core/game.h21
-rw-r--r--src/lua/core/luaopen_core.cpp8
-rw-r--r--src/lua/graphics/luaopen_Canvas.cpp23
-rw-r--r--src/lua/graphics/luaopen_Image.cpp15
-rw-r--r--src/lua/graphics/luaopen_JSL.cpp10
-rw-r--r--src/lua/graphics/luaopen_graphics.cpp3
7 files changed, 56 insertions, 39 deletions
diff --git a/src/core/game.cpp b/src/core/game.cpp
index 6452f48..1c47d87 100644
--- a/src/core/game.cpp
+++ b/src/core/game.cpp
@@ -4,24 +4,11 @@ namespace jin
{
namespace core
{
+
Game* Game::g_game = 0;
Game::Game() :run(true) {};
- Game* Game::get()
- {
- return g_game ? g_game : (g_game = new Game());
- }
-
- void Game::quit()
- {
- run = false;
- }
-
- bool Game::running()
- {
- return run;
- }
}
}
diff --git a/src/core/game.h b/src/core/game.h
index 939d945..d56b249 100644
--- a/src/core/game.h
+++ b/src/core/game.h
@@ -9,12 +9,21 @@ namespace core
{
public:
- void quit();
-
- bool running();
-
- static Game* get();
-
+ static inline Game* get()
+ {
+ return g_game ? g_game : (g_game = new Game());
+ }
+
+ inline void quit()
+ {
+ run = false;
+ }
+
+ inline bool running()
+ {
+ return run;
+ }
+
private:
Game();
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"