summaryrefslogtreecommitdiffstatshomepage
path: root/py/objtuple.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-21 14:14:24 +0000
committerDamien George <damien.p.george@gmail.com>2015-04-21 14:14:24 +0000
commit5aa311d33084c24262780cae0a65d748990ce7e1 (patch)
tree88a87ed9e5a5dcd912fb5e0c9a15ab95a6c465d5 /py/objtuple.h
parent23a2b11abf22d434be17cfce1c491fca0e9c58f2 (diff)
downloadmicropython-5aa311d33084c24262780cae0a65d748990ce7e1.tar.gz
micropython-5aa311d33084c24262780cae0a65d748990ce7e1.zip
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.
Diffstat (limited to 'py/objtuple.h')
-rw-r--r--py/objtuple.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/py/objtuple.h b/py/objtuple.h
index 5fb82ba529..8c4d41ed32 100644
--- a/py/objtuple.h
+++ b/py/objtuple.h
@@ -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__