From 0c2f641c74534054e8aa9a1596c55e075bf8c153 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Wed, 19 Aug 2015 01:36:15 +0200 Subject: [PATCH] Added some values in the gfx lib --- sdcard/ctruLua/main.lua | 2 +- source/gfx.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/sdcard/ctruLua/main.lua b/sdcard/ctruLua/main.lua index 8920a89..29147b4 100644 --- a/sdcard/ctruLua/main.lua +++ b/sdcard/ctruLua/main.lua @@ -38,4 +38,4 @@ while os.run() do if angle > 2*math.pi then angle = angle - 2*math.pi end gfx.render() -end \ No newline at end of file +end diff --git a/source/gfx.c b/source/gfx.c index 3feb733..8ef974f 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -89,6 +89,19 @@ static const struct luaL_Reg gfx_lib[] = { { NULL, NULL } }; +// constants +struct { char *name; int value; } gfx_constants[] = { + { "GFX_TOP", 0 }, + { "GFX_BOTTOM", 1 }, + { "GFX_LEFT", 0 }, + { "GFX_RIGHT", 1 }, + { "TOP_HEIGHT", 240 }, + { "TOP_WIDTH", 400 }, + { "BOTTOM_HEIGHT", 240 }, + { "BOTTOM_WIDTH", 320 }, + { NULL, 0 } +}; + struct { char *name; int (*load)(lua_State *L); } gfx_libs[] = { { "color", load_color_lib }, { NULL, NULL } @@ -96,7 +109,12 @@ struct { char *name; int (*load)(lua_State *L); } gfx_libs[] = { int luaopen_gfx_lib(lua_State *L) { luaL_newlib(L, gfx_lib); - + + for (int i = 0; gfx_constants[i].name; i++) { + lua_pushinteger(L, gfx_constants[i].value); + lua_setfield(L, -2, gfx_constants[i].name); + } + for (int i = 0; gfx_libs[i].name; i++) { gfx_libs[i].load(L); lua_setfield(L, -2, gfx_libs[i].name); @@ -107,4 +125,4 @@ int luaopen_gfx_lib(lua_State *L) { void load_gfx_lib(lua_State *L) { luaL_requiref(L, "ctr.gfx", luaopen_gfx_lib, 0); -} \ No newline at end of file +}