mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Add attrtuple object, for space-efficient tuples with attr access.
If you need the functionality of a namedtuple but will only make 1 or a few instances, then use an attrtuple instead.
This commit is contained in:
@@ -40,4 +40,19 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs);
|
||||
mp_obj_t mp_obj_tuple_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value);
|
||||
mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in);
|
||||
|
||||
extern const mp_obj_type_t mp_type_attrtuple;
|
||||
|
||||
#define MP_DEFINE_ATTRTUPLE(tuple_obj_name, fields, nitems, ...) \
|
||||
const mp_obj_tuple_t tuple_obj_name = { \
|
||||
.base = {&mp_type_attrtuple}, \
|
||||
.len = nitems, \
|
||||
.items = { __VA_ARGS__ , (void*)fields } \
|
||||
}
|
||||
|
||||
#if MICROPY_PY_COLLECTIONS
|
||||
void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_tuple_t *o);
|
||||
#endif
|
||||
|
||||
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, mp_uint_t n, const mp_obj_t *items);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_PY_OBJTUPLE_H__
|
||||
|
||||
Reference in New Issue
Block a user