Apply the beauty of generic mp_obj_t object representation for my small project #17183
Replies: 3 comments 1 reply
-
The problem is that if we pass So I want to utilize that way for my project to generalize objects, its methods, easy maintenance. |
Beta Was this translation helpful? Give feedback.
-
mp_type_type seems to be the base. In nativeglue.c, it is saved to
In file dynruntime.h, it has And in file objtype.c, it has this declaration const mp_obj_type_t mp_type_type
So I could not understand where mp_type_type is. |
Beta Was this translation helpful? Give feedback.
-
As far as building your own project in Arduino, you need to learn about C++ objects (class instances). Virtual functions and polymorphism take care of the casting problem. This is usually handled by having C++ objects contain a (hidden) pointer to a virtual-function table. You can even have RTTI (run-time type information) included if you need to do dynamic casting. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
During using MicroPython, I find it very interesting, especially mp_obj_t concept. It could represent any kind of objects. So I want to use its concept and its partial code base for building my own Arduino C/C++ project, not related to MicroPython. Could someone give me a guide?
For example, I need an object variable, such as obj_t, to represent various of animals, sensors, components, data format (int, float, str, double, int64,...). Normally, we must loop through all animal objects to check for dog type, or cat type,...for further processing. It will become larger and larger if having a lot of animal types to check. It will be difficult to maintain, add more animal type in future,...
It's the same for sensors. There are lots of sensor types in the market. How we could generalize it with one obj_t representation concept.
Thank you so much.
Beta Was this translation helpful? Give feedback.
All reactions