From bdc94208d22dd65d5796264b62d275114489b35e Mon Sep 17 00:00:00 2001 From: Jacob1 Date: Thu, 10 May 2012 17:44:43 -0400 Subject: [PATCH] finish custom lua graphics functions --- includes/luaconsole.h | 2 +- src/graphics.c | 14 +++++++++++++- src/luaconsole.c | 33 +++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/includes/luaconsole.h b/includes/luaconsole.h index 4494ddb97..b4e313b72 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -48,7 +48,7 @@ int luacon_mouseevent(int mx, int my, int mb, int event); int luacon_keyevent(int key, int modifier, int event); int luacon_eval(char *command); int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt); -int luacon_graphics_update(int t, int i); +int luacon_graphics_update(int t, int i, int *pixel_mode, int *cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb); char *luacon_geterror(); void luacon_close(); int luacon_partsread(lua_State* l); diff --git a/src/graphics.c b/src/graphics.c index 60d23b071..0c4c9653f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1860,7 +1860,19 @@ void render_parts(pixel *vid) #ifdef LUACONSOLE if (lua_gr_func[t]) { - colr = luacon_graphics_update(t,i); + if (luacon_graphics_update(t,i, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) + { + graphicscache[t].isready = 1; + graphicscache[t].pixel_mode = pixel_mode; + graphicscache[t].cola = cola; + graphicscache[t].colr = colr; + graphicscache[t].colg = colg; + graphicscache[t].colb = colb; + graphicscache[t].firea = firea; + graphicscache[t].firer = firer; + graphicscache[t].fireg = fireg; + graphicscache[t].fireb = fireb; + } } else if (ptypes[t].graphics_func) { diff --git a/src/luaconsole.c b/src/luaconsole.c index 46168af5a..d32147c3f 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -788,19 +788,28 @@ int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt) } return retval; } -int luacon_graphics_update(int t, int i) +int luacon_graphics_update(int t, int i, int *pixel_mode, int *cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb) { - int retval = 0; - if(lua_gr_func[t]){ - lua_rawgeti(l, LUA_REGISTRYINDEX, lua_gr_func[t]); - lua_pushinteger(l, i); - lua_pcall(l, 1, 1, 0); - if(lua_isnumber(l, -1)){ - retval = (int)lua_tonumber(l, -1); - } - lua_pop(l, 1); - } - return retval; + int cache = 0; + lua_rawgeti(l, LUA_REGISTRYINDEX, lua_gr_func[t]); + lua_pushinteger(l, i); + lua_pushinteger(l, *colr); + lua_pushinteger(l, *colg); + lua_pushinteger(l, *colb); + lua_pcall(l, 4, 10, 0); + + cache = luaL_optint(l, 2, 0); + *pixel_mode = luaL_optint(l, 3, *pixel_mode); + *cola = luaL_optint(l, 4, *cola); + *colr = luaL_optint(l, 5, *colr); + *colg = luaL_optint(l, 6, *colg); + *colb = luaL_optint(l, 7, *colb); + *firea = luaL_optint(l, 8, *firea); + *firer = luaL_optint(l, 9, *firer); + *fireg = luaL_optint(l, 10, *fireg); + *fireb = luaL_optint(l, 11, *fireb); + lua_pop(l, 10); + return cache; } char *luacon_geterror(){ char *error = lua_tostring(l, -1);