a question about import. history library
Posted: Thu Feb 19, 2009 10:12 am
hi, I'm a newbie of newlisp. now I writed one very simple mud client as following.
now it has two problem:
1. if I use readline search function, the program will exit silently. I think it is about memory problem. can anyone fix it ???
2. when the peer of socket close the connection, the program will exit. but I must enter an "\n" before the console returned to shell. why ?
thanks.
this is the probram:
#!/usr/bin/newlisp
;; server
(define mud-server '("pkuxkx.3322.org" 8081))
(context 'greadline)
(import "libhistory.so.5" "add_history")
(import "libreadline.so.5" "readline")
(define (greadline:greadline)
(set 'getted-string-p (readline ""))
(add_history getted-string-p)
(get-string getted-string-p))
(context MAIN)
(set 'server (apply net-connect mud-server))
(fork (begin
(while (net-receive server buffer 8192)
(print buffer))
(letn ((error (net-error))
(error-code (error 0)))
(if (= error-code 6)
(println "bye bye!!")
(print (error 1))))))
(constant 'SIGCHLD 17)
(define (sig_chld_handler)
(wait-pid -1 nil)
(close server)
(exit))
(signal SIGCHLD sig_chld_handler)
(while 1 (net-send server (append (greadline) "\r\n")))
(exit)
now it has two problem:
1. if I use readline search function, the program will exit silently. I think it is about memory problem. can anyone fix it ???
2. when the peer of socket close the connection, the program will exit. but I must enter an "\n" before the console returned to shell. why ?
thanks.
this is the probram:
#!/usr/bin/newlisp
;; server
(define mud-server '("pkuxkx.3322.org" 8081))
(context 'greadline)
(import "libhistory.so.5" "add_history")
(import "libreadline.so.5" "readline")
(define (greadline:greadline)
(set 'getted-string-p (readline ""))
(add_history getted-string-p)
(get-string getted-string-p))
(context MAIN)
(set 'server (apply net-connect mud-server))
(fork (begin
(while (net-receive server buffer 8192)
(print buffer))
(letn ((error (net-error))
(error-code (error 0)))
(if (= error-code 6)
(println "bye bye!!")
(print (error 1))))))
(constant 'SIGCHLD 17)
(define (sig_chld_handler)
(wait-pid -1 nil)
(close server)
(exit))
(signal SIGCHLD sig_chld_handler)
(while 1 (net-send server (append (greadline) "\r\n")))
(exit)