|
26 | 26 |
|
27 | 27 | #include <stdio.h> |
28 | 28 |
|
29 | | -#include "py/nlr.h" |
30 | | -#include "py/obj.h" |
| 29 | +#include "lib/utils/pyhelp.h" |
31 | 30 |
|
32 | 31 | STATIC const char *help_text = |
33 | 32 | "Welcome to MicroPython!\n" |
@@ -72,47 +71,14 @@ STATIC const char *help_text = |
72 | 71 | "For further help on a specific object, type help(obj)\n" |
73 | 72 | ; |
74 | 73 |
|
75 | | -STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { |
76 | | - printf(" "); |
77 | | - mp_obj_print(name_o, PRINT_STR); |
78 | | - printf(" -- "); |
79 | | - mp_obj_print(value, PRINT_STR); |
80 | | - printf("\n"); |
81 | | -} |
82 | | - |
83 | 74 | STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) { |
84 | 75 | if (n_args == 0) { |
85 | 76 | // print a general help message |
86 | 77 | printf("%s", help_text); |
87 | 78 |
|
88 | 79 | } else { |
89 | 80 | // try to print something sensible about the given object |
90 | | - |
91 | | - printf("object "); |
92 | | - mp_obj_print(args[0], PRINT_STR); |
93 | | - printf(" is of type %s\n", mp_obj_get_type_str(args[0])); |
94 | | - |
95 | | - mp_map_t *map = NULL; |
96 | | - if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) { |
97 | | - map = mp_obj_dict_get_map(mp_obj_module_get_globals(args[0])); |
98 | | - } else { |
99 | | - mp_obj_type_t *type; |
100 | | - if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) { |
101 | | - type = args[0]; |
102 | | - } else { |
103 | | - type = mp_obj_get_type(args[0]); |
104 | | - } |
105 | | - if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) { |
106 | | - map = mp_obj_dict_get_map(type->locals_dict); |
107 | | - } |
108 | | - } |
109 | | - if (map != NULL) { |
110 | | - for (uint i = 0; i < map->alloc; i++) { |
111 | | - if (map->table[i].key != MP_OBJ_NULL) { |
112 | | - pyb_help_print_info_about_object(map->table[i].key, map->table[i].value); |
113 | | - } |
114 | | - } |
115 | | - } |
| 81 | + pyhelp_print_obj(args[0]); |
116 | 82 | } |
117 | 83 |
|
118 | 84 | return mp_const_none; |
|
0 commit comments