|
@@ -4,6 +4,8 @@
|
4
|
4
|
#include <math.h>
|
5
|
5
|
#include <stdint.h>
|
6
|
6
|
#include <dlfcn.h>
|
|
7
|
+#include <readline/readline.h>
|
|
8
|
+#include <readline/history.h>
|
7
|
9
|
#include "ast.h"
|
8
|
10
|
#include "dsl/dsl.h"
|
9
|
11
|
|
|
@@ -458,6 +460,35 @@ sol_object_t *sol_f_debug_scopes(sol_state_t *state, sol_object_t *args) {
|
458
|
460
|
return sol_incref(state->scopes);
|
459
|
461
|
}
|
460
|
462
|
|
|
463
|
+sol_object_t *sol_f_readline_readline(sol_state_t *state, sol_object_t *args) {
|
|
464
|
+ sol_object_t *obj, *objstr, *res;
|
|
465
|
+ char *line;
|
|
466
|
+ if(sol_list_len(state, args) > 0) {
|
|
467
|
+ obj = sol_list_get_index(state, args, 0);
|
|
468
|
+ objstr = sol_cast_string(state, obj);
|
|
469
|
+ line = readline(objstr->str);
|
|
470
|
+ sol_obj_free(obj);
|
|
471
|
+ sol_obj_free(objstr);
|
|
472
|
+ } else {
|
|
473
|
+ line = readline("");
|
|
474
|
+ }
|
|
475
|
+ if(line) {
|
|
476
|
+ res = sol_new_string(state, line);
|
|
477
|
+ free(line);
|
|
478
|
+ } else {
|
|
479
|
+ res = sol_new_string(state, "");
|
|
480
|
+ }
|
|
481
|
+ return res;
|
|
482
|
+}
|
|
483
|
+
|
|
484
|
+sol_object_t *sol_f_readline_add_history(sol_state_t *state, sol_object_t *args) {
|
|
485
|
+ sol_object_t *line = sol_list_get_index(state, args, 0), *linestr = sol_cast_string(state, line);
|
|
486
|
+ add_history(linestr->str);
|
|
487
|
+ sol_obj_free(linestr);
|
|
488
|
+ sol_obj_free(line);
|
|
489
|
+ return sol_incref(state->None);
|
|
490
|
+}
|
|
491
|
+
|
461
|
492
|
void _sol_freef_seq_iter(void *iter, size_t sz) {
|
462
|
493
|
dsl_free_seq_iter((dsl_seq_iter *) iter);
|
463
|
494
|
}
|