readline vs. editline
Asko Kauppi <[email protected]> Fri, 28 May 2004 14:14:31 +0300
| Newsgroups | gmane.comp.lang.lua.luacheia |
|---|---|
| Message-ID | <[email protected]> |
Hi, all.
I've moved location (within finland) and back on track with LuaX work..
Here's an issue that might be interesting to you, and/or a help
request:
a) Readline is nice, but GPL
b) BSD libedit does the same, not GPL
c) libedit has readline compatibility _but_not_on_OS_X
d) native libedit coding sucks :)
So, what I'm trying to do is a simple two-function wrapper ('readline'
and 'add_history') that would use OS X native libedit instead. The
code compiles, but does not work as it should. For example, history
lines are not available.
What am I doing wrong, here??
-ak
#ifndef PLATFORM_DARWIN // Linux has readline compatibility (OS X
has not!)
#include <readline/readline.h>
#include <readline/history.h>
#define readline_free free
#else
#include <histedit.h> // see 'man editline'
//
static EditLine* el= NULL;
static History* hist= NULL;
static const char* pr= NULL;
//
const char* f_prompt( EditLine* e ) { return pr; }
//
static char* readline( const char* prompt )
{
if (!el) el= el_init( "gluahost" /*prog*/, stdin, stdout, stderr
);
ASSUME(el);
pr= prompt; el_set( el, EL_PROMPT, f_prompt );
int count;
return (char*)el_gets( el, &count );
}
//
static void add_history( char* buffer )
{
if (!hist) hist= history_init();
ASSUME( hist && el );
{
HistEvent ev;
int rc= history( hist, &ev, H_APPEND, buffer );
ASSUME( rc==0 ); // success?
}
}
//
#define readline_free(p) /*nothing*/
#endif // Darwin
#endif
#if (defined USE_READLINE) || (defined USE_EDITLINE)
//
#define lua_readline(L,prompt) _lua_readline(L,prompt) // for
'lua.c'
//
static int _lua_readline( lua_State *L, const char *prompt )
{
/*const*/ char* buffer;
buffer= readline(prompt);
if (!buffer) return 0; // read fails
if (buffer[0]) add_history(buffer); // remember the line
lua_pushstring( L, buffer );
readline_free(buffer); // sort of essential.. ;)
return 1;
}
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click