1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added ctr.gfx.color lib; color.setDefault and color.getDefault working

This commit is contained in:
Reuh 2015-08-18 16:19:11 +02:00
parent 2584e46816
commit 3441dd266f
3 changed files with 53 additions and 2 deletions

View file

@ -3,7 +3,9 @@
#include <lua.h>
#include <lauxlib.h>
u32 defaultColor = RGBA8(255, 255, 255, 255);
int load_color_lib(lua_State *L);
u32 color_default;
static int gfx_startFrame(lua_State *L) {
sf2d_start_frame(GFX_TOP, GFX_LEFT);
@ -28,7 +30,7 @@ static int gfx_rectangle(lua_State *L) {
int y = luaL_checkinteger(L, 2);
int width = luaL_checkinteger(L, 3);
int height = luaL_checkinteger(L, 4);
u32 color = luaL_optinteger(L, 5, defaultColor);
u32 color = luaL_optinteger(L, 5, color_default);
sf2d_draw_rectangle(x, y, width, height, color);
@ -43,8 +45,19 @@ static const struct luaL_Reg gfx_lib[] = {
{ NULL, NULL }
};
struct { char *name; int (*load)(lua_State *L); } gfx_libs[] = {
{ "color", load_color_lib },
{ NULL, NULL }
};
int luaopen_gfx_lib(lua_State *L) {
luaL_newlib(L, gfx_lib);
for (int i = 0; gfx_libs[i].name; i++) {
gfx_libs[i].load(L);
lua_setfield(L, -2, gfx_libs[i].name);
}
return 1;
}