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
This commit is contained in:
Kartik K. Agaram 2021-10-22 21:22:27 -07:00
parent 05fa5124c2
commit 8d8580089f
1 changed files with 7 additions and 10 deletions

View File

@ -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;
}