2 /* Jim - Readline bindings for Jim
3 * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * A copy of the license is also included in the source distribution
12 * of Jim, as a TXT file name called LICENSE.
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "jimautoconf.h"
24 #include <readline/readline.h>
25 #include <readline/history.h>
27 static int JimRlReadlineCommand(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
32 Jim_WrongNumArgs(interp
, 1, argv
, "prompt");
35 line
= readline(Jim_String(argv
[1]));
39 Jim_SetResult(interp
, Jim_NewStringObj(interp
, line
, -1));
43 static int JimRlAddHistoryCommand(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
46 Jim_WrongNumArgs(interp
, 1, argv
, "string");
49 add_history(Jim_String(argv
[1]));
53 int Jim_readlineInit(Jim_Interp
*interp
)
55 if (Jim_PackageProvide(interp
, "readline", "1.0", JIM_ERRMSG
))
58 Jim_CreateCommand(interp
, "readline.readline", JimRlReadlineCommand
, NULL
, NULL
);
59 Jim_CreateCommand(interp
, "readline.addhistory", JimRlAddHistoryCommand
, NULL
, NULL
);