`getstr` in ncurses egg (Chicken Scheme)

Viewed 170

I'm trying to figure how to use the function getstr of this egg (and consequently of mvgetstr, mvwgetstr, etc...). For example:

(require-extension ncurses)

(let ((stdscr (initscr)) (str (make-string 10)))
  (getstr str)
  (addstr str)
  (getch))

csi tells me

Error: bad argument type - not a pointer: " "

So i tried with this:

(require-extension ncurses)

(let ((stdscr (initscr)) (str (make-string 10)))
  (begin      
  (getstr (object->pointer str))
   (addstr str)
   (getch)))) 

This time csi give me another error:

Error: bad argument type - not a string: [panic] Detected corrupted data in stack - execution terminated

I think the problem is about the encoding of the string (a function thinks is ascii and another utf-8). I've no experience with pointer in scheme, I simply would know the best idiot-proof way to get a string with this egg.

2 Answers

This seems to work for version 5 of Chicken Scheme:

(import ncurses
     (chicken locative)
     (chicken string))

(let ((stdscr (initscr)) (str (make-string 10)))
    (getstr (make-locative str))
    (addstr (string-translate str #\null))
    (getch)
    (endwin))
Related