aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 639a542..24cdf59 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -164,7 +164,7 @@ namespace JinEngine
return 1;
}
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_BITMAP);
proxy->bind(new Shared<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
}
@@ -185,7 +185,7 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXTURE);
proxy->bind(new Shared<Texture>(texture, JIN_GRAPHICS_TEXTURE));
return 1;
}
@@ -200,7 +200,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_SHADER);
proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -224,7 +224,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_SHADER);
proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -233,7 +233,7 @@ namespace JinEngine
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_CANVAS);
Canvas* cvs = Canvas::createCanvas(w, h);
proxy->bind(new Shared<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
return 1;
@@ -462,8 +462,8 @@ namespace JinEngine
return 0;
}
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Shared<Canvas>& ref = proxy->getShared<Canvas>();
- Canvas::bind(ref.getObject());
+ Shared<Canvas>& shared = proxy->getShared<Canvas>();
+ Canvas::bind(shared.getObject());
return 0;
}
@@ -496,10 +496,18 @@ namespace JinEngine
LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
- return 0;
+ return 0;
}
-#define IntToRenderMode(I) static_cast<RenderMode>(I)
+ LUA_IMPLEMENT RenderMode strtomode(const char* str)
+ {
+ std::string s = std::string(str);
+ if (s == "fill")
+ return RenderMode::FILL;
+ else if (s == "line")
+ return RenderMode::LINE;
+ else return RenderMode::NONE;
+ }
LUA_IMPLEMENT int l_point(lua_State* L)
{
@@ -523,7 +531,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_rect(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -543,7 +552,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_circle(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -562,7 +572,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -587,8 +598,9 @@ namespace JinEngine
LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
- int n = luax_checknumber(L, 2);
+ const char* modestr = luax_checkstring(L, 1);
+ int n = luax_checknumber(L, 2);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -621,7 +633,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TTFDATA);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
@@ -659,7 +671,7 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXT);
proxy->bind(new Shared<Text>(text, JIN_GRAPHICS_TEXT));
return 1;
}
@@ -711,7 +723,7 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT);
proxy->bind(new Shared<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
return 1;
}
@@ -798,7 +810,7 @@ namespace JinEngine
LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // Register types.
+ // register types
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -809,7 +821,7 @@ namespace JinEngine
luaopen_Page(L);
luaopen_JSL(L);
- // Load whole lib.
+ // load whole lib
luax_newlib(L, f);
return 1;