mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #674 from mattn/readline
use readline if it's enabled.
This commit is contained in:
+14
-1
@@ -12,6 +12,10 @@
|
||||
#include <mruby/proc.h>
|
||||
#include <mruby/data.h>
|
||||
#include <mruby/compile.h>
|
||||
#ifdef ENABLE_READLINE
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_STDIO
|
||||
#include <mruby/string.h>
|
||||
@@ -143,10 +147,12 @@ print_cmdline(int code_block_open)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int last_char;
|
||||
char ruby_code[1024] = { 0 };
|
||||
char last_code_line[1024] = { 0 };
|
||||
#ifndef ENABLE_READLINE
|
||||
int last_char;
|
||||
int char_index;
|
||||
#endif
|
||||
mrbc_context *cxt;
|
||||
struct mrb_parser_state *parser;
|
||||
mrb_state *mrb;
|
||||
@@ -167,6 +173,7 @@ main(void)
|
||||
cxt->capture_errors = 1;
|
||||
|
||||
while (TRUE) {
|
||||
#ifndef ENABLE_READLINE
|
||||
print_cmdline(code_block_open);
|
||||
|
||||
char_index = 0;
|
||||
@@ -180,6 +187,12 @@ main(void)
|
||||
}
|
||||
|
||||
last_code_line[char_index] = '\0';
|
||||
#else
|
||||
char* line = readline(code_block_open ? "* " : "> ");
|
||||
strncat(last_code_line, line, sizeof(last_code_line)-1);
|
||||
add_history(line);
|
||||
free(line);
|
||||
#endif
|
||||
|
||||
if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) {
|
||||
if (!code_block_open) {
|
||||
|
||||
Reference in New Issue
Block a user