Merge pull request #217 from dubek/lua-interop
[jackhill/mal.git] / objpascal / mal_readline.pas
1 unit mal_readline;
2
3 {$H+} // Use AnsiString
4
5 interface
6
7 uses sysutils,
8 CTypes;
9
10 {$IFDEF USE_READLINE}
11
12 {$LINKLIB readline}
13
14 {$ELSE}
15
16 {$LINKLIB libedit}
17
18 {$ENDIF}
19
20
21 // External libedit/readline functions
22
23 function readline(Prompt: PChar) : PChar; cdecl; external;
24 procedure add_history(Line: PChar); cdecl; external;
25
26 // API
27
28 type MalEOF = class(Exception);
29
30 function _readline(Prompt: string) : string;
31
32 ////////////////////////////////////////////////////////////
33
34 implementation
35
36 function _readline(Prompt: string) : string;
37 var
38 Line : PChar;
39 begin
40 Line := readline(PChar(Prompt));
41 if Line = Nil then
42 raise MalEOF.Create('MalEOF');
43 if Line <> '' then
44 add_history(Line);
45
46 _readline := Line;
47 end;
48
49 end.