aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-03-18 07:17:44 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-03-18 07:17:44 -0500
commit294bdec0c0efb9d1bdb3a495ebf3d602e3ee4fc2 (patch)
tree84f175f4ee64fb9527baf0c2576df85407b4e8d0
parent82a357057ce5c3f1a89809ce397e0477b19b00b0 (diff)
downloadluancurses-294bdec0c0efb9d1bdb3a495ebf3d602e3ee4fc2.tar.gz
luancurses-294bdec0c0efb9d1bdb3a495ebf3d602e3ee4fc2.zip
implement init_color
-rw-r--r--src/curses.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/curses.c b/src/curses.c
index cc3530c..ee0e03a 100644
--- a/src/curses.c
+++ b/src/curses.c
@@ -206,8 +206,47 @@ static int l_setup_term(lua_State* L)
static int l_init_color(lua_State* L)
{
- /* test can_change_color here */
- return 0;
+ const char* name;
+ int color_val;
+ short r, g, b;
+
+ if (can_change_color() == FALSE) {
+ lua_pushboolean(L, FALSE);
+ return 1;
+ }
+
+ name = luaL_checklstring(L, 1, NULL);
+
+ lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE);
+ lua_getfield(L, -1, "colors");
+ lua_getfield(L, -1, name);
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 1);
+ lua_pushinteger(L, ++ncolors);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -3, name);
+ }
+ color_val = lua_tointeger(L, -1);
+ lua_pop(L, 2);
+
+ if (lua_istable(L, 2)) {
+ lua_getfield(L, 2, "r");
+ lua_getfield(L, 2, "g");
+ lua_getfield(L, 2, "b");
+ r = luaL_checkinteger(L, -3) * 1000 / 256;
+ g = luaL_checkinteger(L, -2) * 1000 / 256;
+ b = luaL_checkinteger(L, -1) * 1000 / 256;
+ lua_pop(L, 3);
+ }
+ else {
+ r = luaL_checkinteger(L, 2) * 1000 / 256;
+ g = luaL_checkinteger(L, 3) * 1000 / 256;
+ b = luaL_checkinteger(L, 4) * 1000 / 256;
+ }
+
+ lua_pushboolean(L, init_color(color_val, r, g, b) == OK);
+
+ return 1;
}
static int l_init_pair(lua_State* L)