From 4b7d8b7ef50d1bcdf5de02bb737d585fc4950a75 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Tue, 18 Mar 2008 15:11:44 -0500 Subject: implement use_default_colors and assume_default_colors as functions available to lua rather than calling use_default_colors automatically in start_color --- src/curses.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/curses.c b/src/curses.c index 23a0a69..564bdbf 100644 --- a/src/curses.c +++ b/src/curses.c @@ -55,6 +55,16 @@ static void register_color(const char* color_str, int color_tag, void* data) ncolors++; } +static void register_default_color(lua_State* L) +{ + lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE); + lua_getfield(L, -1, "colors"); + lua_pushinteger(L, -1); + lua_setfield(L, -2, "default"); + lua_pop(L, 2); + default_color_available = 1; +} + static void init_colors(lua_State* L) { lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE); @@ -162,7 +172,6 @@ static int l_start_color(lua_State* L) init_color_pairs(L); init_colors(L); lua_pushboolean(L, start_color() == OK); - use_default_colors(); } else { lua_pushboolean(L, FALSE); @@ -171,6 +180,38 @@ static int l_start_color(lua_State* L) return 1; } +static int l_use_default_colors(lua_State* L) +{ + register_default_color(L); + lua_pushboolean(L, use_default_colors() == OK); + return 1; +} + +static int l_assume_default_colors(lua_State* L) +{ + const char* fg; + const char* bg; + int nfg, nbg; + + register_default_color(L); + + fg = luaL_optlstring(L, 1, "default", NULL); + bg = luaL_optlstring(L, 2, "default", NULL); + + lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE); + lua_getfield(L, -1, "colors"); + lua_getfield(L, -1, fg); + nfg = luaL_checkint(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, bg); + nbg = luaL_checkint(L, -1); + lua_pop(L, 3); + + lua_pushboolean(L, assume_default_colors(nfg, nbg) == OK); + return 1; +} + static int l_setup_term(lua_State* L) { int ret = 0; @@ -615,6 +656,8 @@ const luaL_Reg reg[] = { { "endwin", l_endwin }, { "isendwin", l_isendwin }, { "start_color", l_start_color }, + { "use_default_colors", l_use_default_colors }, + { "assume_default_colors", l_assume_default_colors }, { "setup_term", l_setup_term }, { "init_color", l_init_color }, { "init_pair", l_init_pair }, -- cgit v1.2.3-54-g00ecf