Numworks Epsilon  1.4.1
Graphing Calculator Operating System
builtins.c
Go to the documentation of this file.
1 #include "py/builtin.h"
2 #include "py/obj.h"
3 #include <string.h>
4 #include "mphalport.h"
5 
6 mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
7  return mp_const_none;
8 }
9 MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
10 
11 mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) {
12  // 1 - Retrieve the prompt if any
13  const char * prompt = NULL;
14  if (n_args == 1) {
15  prompt = mp_obj_str_get_str(args[0]);
16  }
17 
18  // 2 - Perform the HAL input command
19  const char * result = mp_hal_input(prompt);
20 
21  // 3 - Log the prompt, result and flush a new line
22  mp_obj_t resultStr = mp_obj_new_str(result, strlen(result), false);
23  if (n_args == 1) {
25  }
26  mp_obj_print(resultStr, PRINT_STR);
28 
29  return resultStr;
30 }
31 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input);
#define mp_const_none
Definition: obj.h:614
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input)
void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind)
Definition: obj.c:76
int mp_print_str(const mp_print_t *print, const char *str)
Definition: mpprint.c:53
size_t strlen(const char *s)
Definition: strlen.c:3
#define NULL
Definition: stddef.h:4
#define MP_PYTHON_PRINTER
Definition: mpprint.h:45
mp_obj_t mp_obj_new_str(const char *data, size_t len, bool make_qstr_if_not_already)
Definition: objstr.c:2025
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
Definition: builtins.c:6
args
Definition: i18n.py:175
Definition: obj.h:356
const char * mp_obj_str_get_str(mp_obj_t self_in)
Definition: objstr.c:2095
Definition: obj.h:413
const char * mp_hal_input(const char *prompt)
Definition: port.cpp:171
uint64_t mp_obj_t
Definition: obj.h:39
mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args)
Definition: builtins.c:11
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open)