From c33af6540c15de67b98e1d490ef1853526cc4c79 Mon Sep 17 00:00:00 2001 From: jaeger Date: Sun, 10 Feb 2013 18:11:36 +0000 Subject: [PATCH] tinypy: support for raw_input() builtin function. git-svn-id: svn://kolibrios.org@3235 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/tinypy/tinypy/builtins.c | 13 +++++++++++++ programs/develop/tinypy/tinypy/vm.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/programs/develop/tinypy/tinypy/builtins.c b/programs/develop/tinypy/tinypy/builtins.c index ded28dbaea..772db059ad 100644 --- a/programs/develop/tinypy/tinypy/builtins.c +++ b/programs/develop/tinypy/tinypy/builtins.c @@ -10,6 +10,19 @@ tp_obj tp_print(TP) { return tp_None; } +#define BUF_SIZE 2048 +tp_obj tp_raw_input(TP) { + tp_obj prompt; + char *buf = malloc(BUF_SIZE); + if (tp->params.list.val->len) + { + prompt = TP_OBJ(); + con_printf("%s", TP_CSTR(prompt)); + } + con_gets(buf, BUF_SIZE); + return tp_string(buf); +} + tp_obj tp_bind(TP) { tp_obj r = TP_OBJ(); tp_obj self = TP_OBJ(); diff --git a/programs/develop/tinypy/tinypy/vm.c b/programs/develop/tinypy/tinypy/vm.c index c5fa0e2588..107a80c856 100644 --- a/programs/develop/tinypy/tinypy/vm.c +++ b/programs/develop/tinypy/tinypy/vm.c @@ -325,8 +325,8 @@ tp_obj tp_import_(TP) { void tp_builtins(TP) { struct {const char *s;void *f;} b[] = { - {"print",tp_print}, {"range",tp_range}, {"min",tp_min}, - {"max",tp_max}, {"bind",tp_bind}, {"copy",tp_copy}, + {"print",tp_print}, {"range",tp_range}, {"raw_input", tp_raw_input}, + {"min",tp_min}, {"max",tp_max}, {"bind",tp_bind}, {"copy",tp_copy}, {"import",tp_import_}, {"len",tp_len_}, {"assert",tp_assert}, {"str",tp_str2}, {"float",tp_float}, {"system",tp_system}, {"istype",tp_istype}, {"chr",tp_chr}, {"save",tp_save},