about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-10-22 21:22:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-10-22 21:22:27 -0700
commit8d8580089f177192b895b302275677d25af4e629 (patch)
tree05ec60b03964f11583b928c33fcf480f0b51a88f
parent05fa5124c24a00efb2dc0b760fbf3edc4f3f060a (diff)
downloadteliva-8d8580089f177192b895b302275677d25af4e629.tar.gz
print's newline now returns to column 0
At this point I'm done making this repo ncurses-ready. Remaining files
that allude to stdin/stdout/stderr:

  lauxlib.c - unclear how these primitives should work; may kill them
  ldblib.c - unclear what debug experience should be
  liolib.c - might kill or simulate these
  luac.c - let the compiler continue to be a terminal program
-rw-r--r--src/lbaselib.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/lbaselib.c b/src/lbaselib.c
index 2ab550b..fa597eb 100644
--- a/src/lbaselib.c
+++ b/src/lbaselib.c
@@ -7,6 +7,7 @@
 
 
 #include <ctype.h>
+#include <ncurses.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -22,15 +23,9 @@
 
 
 
-/*
-** If your system does not support `stdout', you can just remove this function.
-** If you need, you can define your own `print' function, following this
-** model but changing `fputs' to put the strings at a proper place
-** (a console window or a log file, for instance).
-*/
 static int luaB_print (lua_State *L) {
   int n = lua_gettop(L);  /* number of arguments */
-  int i;
+  int i, y, x;
   lua_getglobal(L, "tostring");
   for (i=1; i<=n; i++) {
     const char *s;
@@ -41,11 +36,13 @@ static int luaB_print (lua_State *L) {
     if (s == NULL)
       return luaL_error(L, LUA_QL("tostring") " must return a string to "
                            LUA_QL("print"));
-    if (i>1) fputs("\t", stdout);
-    fputs(s, stdout);
+    if (i>1) addstr("\t");
+    addstr(s);
     lua_pop(L, 1);  /* pop result */
   }
-  fputs("\n", stdout);
+  getyx(stdscr, y, x);
+  mvprintw(y+1, x=0, "");
+  refresh();
   return 0;
 }