mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #987 from openmv/py_helper
Add py_helper function to lookup an iterable.
This commit is contained in:
commit
8e14372d61
@ -243,6 +243,26 @@ float *py_helper_keyword_corner_array(uint n_args, const mp_obj_t *args, uint ar
|
|||||||
return NULL;
|
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)
|
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)) {
|
if (MP_OBJ_IS_TYPE(args[arg_index], &mp_type_tuple) || MP_OBJ_IS_TYPE(args[arg_index], &mp_type_list)) {
|
||||||
|
|||||||
@ -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);
|
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,
|
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_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);
|
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,
|
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);
|
mp_map_t *kw_args, int default_val);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user