about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-05 10:51:47 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-05 10:51:47 -0700
commitf761d0ae366333ab191d3a251336e21f16102eb2 (patch)
tree3d4f3c2b56a5c06d9603878a7ce8c782e1a69ea3 /src
parent8552ad4ced8ccd0cf5276bf6d03f0c43028be8af (diff)
downloadteliva-f761d0ae366333ab191d3a251336e21f16102eb2.tar.gz
stdscr binding
print(curses.stdscr())
print(curses:stdscr())
Diffstat (limited to 'src')
-rw-r--r--src/lcurseslib.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index d8667fc..c7b1c27 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -6,6 +6,13 @@
 #include "lualib.h"
 
 
+static int Pstdscr(lua_State *L) {
+  lua_pushstring(L, "curses:stdscr");
+  lua_rawget(L, LUA_REGISTRYINDEX);
+  return 1;
+}
+
+
 static int Pcols(lua_State *L) {
   lua_pushinteger(L, COLS);
   return 1;
@@ -14,6 +21,7 @@ static int Pcols(lua_State *L) {
 
 static const struct luaL_Reg curseslib [] = {
   {"cols", Pcols},
+  {"stdscr", Pstdscr},
   {NULL, NULL}
 };
 
@@ -34,7 +42,11 @@ static void curses_newwin (lua_State *L, WINDOW *nw) {
 
 LUALIB_API int luaopen_curses (lua_State *L) {
   luaL_register(L, "curses", curseslib);
+  /* save main window on registry */
   curses_newwin(L, stdscr);
+  lua_pushstring(L, "curses:stdscr");
+  lua_pushvalue(L, -2);
+  lua_rawset(L, LUA_REGISTRYINDEX);
   return 1;
 }