Merge pull request #987 from openmv/py_helper

Add py_helper function to lookup an iterable.
This commit is contained in:
Ibrahim Abd Elkader 2020-11-20 19:17:27 +02:00 committed by GitHub
commit 8e14372d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -243,6 +243,26 @@ float *py_helper_keyword_corner_array(uint n_args, const mp_obj_t *args, uint ar
return NULL;
}
mp_obj_t *py_helper_keyword_iterable(uint n_args, const mp_obj_t *args,
uint arg_index, mp_map_t *kw_args, mp_obj_t kw, size_t *len)
{
mp_obj_t itr = NULL;
mp_obj_t *items = NULL;
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
if (kw_arg) {
itr = kw_arg->value;
} else if (n_args > arg_index) {
itr = args[arg_index];
}
if (itr && (MP_OBJ_IS_TYPE(itr, &mp_type_tuple) ||
MP_OBJ_IS_TYPE(itr, &mp_type_list))) {
mp_obj_get_array(itr, len, &items);
}
return items;
}
uint py_helper_consume_array(uint n_args, const mp_obj_t *args, uint arg_index, size_t len, const mp_obj_t **items)
{
if (MP_OBJ_IS_TYPE(args[arg_index], &mp_type_tuple) || MP_OBJ_IS_TYPE(args[arg_index], &mp_type_list)) {

View File

@ -43,6 +43,8 @@ void py_helper_keyword_float_array(uint n_args, const mp_obj_t *args, uint arg_i
mp_map_t *kw_args, mp_obj_t kw, float *x, int size);
float *py_helper_keyword_corner_array(uint n_args, const mp_obj_t *args, uint arg_index,
mp_map_t *kw_args, mp_obj_t kw);
mp_obj_t *py_helper_keyword_iterable(uint n_args, const mp_obj_t *args, uint arg_index,
mp_map_t *kw_args, mp_obj_t kw, size_t *len);
uint py_helper_consume_array(uint n_args, const mp_obj_t *args, uint arg_index, size_t len, const mp_obj_t **items);
int py_helper_keyword_color(image_t *img, uint n_args, const mp_obj_t *args, uint arg_index,
mp_map_t *kw_args, int default_val);