aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-09-06 21:55:26 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-09-06 21:55:26 -0500
commit054680ddf98ecc61ea87d8a28660ed94a318a938 (patch)
treea6e42fc01ecaa40fdd6f5f8a4dea0f88b054afcd
parent15147ea6e882c95b1bdc9c4d41f794a462c7b3d5 (diff)
downloadluancurses-054680ddf98ecc61ea87d8a28660ed94a318a938.tar.gz
luancurses-054680ddf98ecc61ea87d8a28660ed94a318a938.zip
beginnings of a lua interface
-rw-r--r--src/curses.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/curses.c b/src/curses.c
new file mode 100644
index 0000000..ff90ef5
--- /dev/null
+++ b/src/curses.c
@@ -0,0 +1,90 @@
+#include <curses.h>
+#include <lua.h>
+
+/* necessary because atexit() expects a function that returns void, and gcc
+ * whines otherwise */
+static void _endwin(void)
+{
+ endwin();
+}
+
+static int l_initialize(lua_State* L)
+{
+ int ret;
+
+ /* XXX: do we want to do this? how important is cleaning up? */
+ signal(SIGTERM, exit);
+ atexit(_endwin);
+ ret = initscr();
+ if (has_colors()) {
+ start_color();
+ }
+
+ lua_pushboolean(L, ret == OK);
+ return 1;
+}
+
+static int l_initscr(lua_State* L)
+{
+ lua_pushboolean(L, initscr() == OK);
+ return 1;
+}
+
+static int l_setup_term(lua_State* L)
+{
+ int ret = 0;
+
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_pushnil(L);
+ while (lua_next(L, t) != 0) {
+ if (lua_isstring(L, -2)) {
+ char* str;
+
+ str = lua_tostring(L, -2);
+ /* XXX: this certainly needs expansion */
+ if (!strcmp(str, "nl")) {
+ ret += ((lua_toboolean(L, -1) ? nl() : nonl()) == OK);
+ }
+ else if (!strcmp(str, "cbreak")) {
+ ret += ((lua_toboolean(L, -1) ? cbreak() : nocbreak()) == OK);
+ }
+ else if (!strcmp(str, "echo")) {
+ ret += ((lua_toboolean(L, -1) ? echo() : noecho()) == OK);
+ }
+ else if (!strcmp(str, "keypad")) {
+ ret += ((keypad(stdscr, lua_toboolean(L, -1))) == OK);
+ }
+ else {
+ luaL_error(L, "Unknown or unimplemented terminal mode %s", str);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ lua_pushnumber(L, ret);
+ return 1;
+}
+
+static int l_init_pair(lua_State* L)
+{
+}
+
+static int l_getch(lua_State* L)
+{
+}
+
+static int l_move(lua_State* L)
+{
+}
+
+static int l_addch(lua_State* L)
+{
+}
+
+static int l_refresh(lua_State* L)
+{
+}
+
+int luaopen_ncurses(lua_State* L)
+{
+}