Firas_Baccouri
wrote:
↑
Thu Jun 23, 2022 1:00 pm
ah , ok , so I went to check into the micropython firmware about : mp_get_buffer() and mp_getiter() :
1 :it might be there are some documentation missed because I didn´t understand all the parameters of both of that two functions .
2 :This two functions returns a mp_obj_t , so I want to know how my list , bytearray ,str ... is stored into a variable of mp_obj_t so I can Know how I can itterate it to use each element of it .
Yes, this is an area of the documentation that is very lacking. Mostly you have to learn this by looking at existing code. Generally what I recommend is thinking of a Python standard library function that behaves similarly to what you want, and then go and look at the code that implements that.
The key thing is that an mp_obj_t is just a number that can either represent a small integer, an interned string, or a pointer to a Python object (i.e. a pointer to a struct that has `mp_obj_base_t base;` as its first member). For the details of how mp_obj_t works, see
https://github.com/micropython/micropyt ... nfig.h#L93
So a function that is exposed to Python must take all its arguments as mp_obj_t and return an mp_obj_t. You can construct an mp_obj_t using methods like mp_obj_new_int or mp_obj_new_str or MP_OBJ_FROM_PTR. You can convert an mp_obj_t into whatever you need using methods like mp_get_buffer, mp_getiter, mp_obj_get_type, MP_OBJ_TO_PTR, etc.
So for example, if you have a argument that is a list (or tuple, or anything that is iterable, i.e. you could use with a `for` loop in Python), and you just want to iterate it, then you use mp_getiter.
Unfortunately I don't quite understand what your function does or what the arguments are, otherwise I could give you more specific hints about which methods you need to use.