aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-09-08 14:06:21 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-09-08 14:06:21 -0500
commitcba97e8fa134b39baf9242b9a1d8c3559dc8e8c8 (patch)
treeea5639859a9070b9f6dbceb064e766698c8560ea
parenta822647b9ccaa56c6ae9353470bb77737ab532d8 (diff)
downloadluancurses-cba97e8fa134b39baf9242b9a1d8c3559dc8e8c8.tar.gz
luancurses-cba97e8fa134b39baf9242b9a1d8c3559dc8e8c8.zip
differentiate addstr and addch (so that i can use addch to add special characters later
-rw-r--r--src/curses.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/curses.c b/src/curses.c
index a00c0d3..904b4e4 100644
--- a/src/curses.c
+++ b/src/curses.c
@@ -113,6 +113,12 @@ static int get_mode(lua_State* L, const char* str)
return A_NORMAL;
}
+static chtype get_char(const char* str)
+{
+ /* add the ACS_ defines here */
+ return str[0];
+}
+
static int get_char_attr(lua_State* L, int stack_pos)
{
int mode = A_NORMAL;
@@ -343,6 +349,32 @@ static int l_move(lua_State* L)
return 1;
}
+static int l_addch(lua_State* L)
+{
+ int is_mv;
+ pos p;
+ size_t l;
+ attr_t mode = 0;
+ short color = 0;
+ chtype ch;
+
+ is_mv = get_pos(L, &p);
+ ch = get_char(luaL_checklstring(L, 1, &l));
+ if (lua_istable(L, 2)) {
+ mode = get_char_attr(L, 2);
+ color = get_char_color(L, 2);
+ }
+
+ if (is_mv) {
+ lua_pushboolean(L, mvaddch(p.y, p.x, ch | mode | color) == OK);
+ }
+ else {
+ lua_pushboolean(L, addch(ch | mode | color) == OK);
+ }
+
+ return 1;
+}
+
static int l_addstr(lua_State* L)
{
int is_mv, set_attrs = 0;
@@ -361,20 +393,10 @@ static int l_addstr(lua_State* L)
}
if (is_mv) {
- if (l == 1) {
- lua_pushboolean(L, mvaddch(p.y, p.x, *str) == OK);
- }
- else {
- lua_pushboolean(L, mvaddstr(p.y, p.x, str) == OK);
- }
+ lua_pushboolean(L, mvaddstr(p.y, p.x, str) == OK);
}
else {
- if (l == 1) {
- lua_pushboolean(L, addch(*str) == OK);
- }
- else {
- lua_pushboolean(L, addstr(str) == OK);
- }
+ lua_pushboolean(L, addstr(str) == OK);
}
if (set_attrs) {
@@ -432,6 +454,7 @@ const luaL_Reg reg[] = {
{ "init_pair", l_init_pair },
{ "getch", l_getch },
{ "move", l_move },
+ { "addch", l_addch },
{ "addstr", l_addstr },
{ "refresh", l_refresh },
{ "getmaxyx", l_getmaxyx },