summaryrefslogtreecommitdiffstatshomepage
path: root/examples/usercmodule/cppexample/examplemodule.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-05-10 13:22:54 +1000
committerDamien George <damien@micropython.org>2023-06-01 16:21:37 +1000
commited90f30dd5d39e958ce99c041f1dc1f9dbb63bb2 (patch)
tree9394f2480b961b4e6836dda72180eb36e27d6030 /examples/usercmodule/cppexample/examplemodule.c
parent525557738cccb73d7b00d2048b9fd47e4caeeec6 (diff)
downloadmicropython-ed90f30dd5d39e958ce99c041f1dc1f9dbb63bb2.tar.gz
micropython-ed90f30dd5d39e958ce99c041f1dc1f9dbb63bb2.zip
py/builtinimport: Allow builtin modules to be packages.
To use this: - Create a built-in module, and add the module object as a member of the parent module's globals dict. - The submodule can set its `__name__` to either `QSTR_foo_dot_bar` or `QSTR_bar`. The former requires using qstrdefs(port).h to make the qstr. Because `bar` is a member of `foo`'s globals, it is possible to write `import foo` and then immediately use `foo.bar` without importing it explicitly. This means that if `bar` has an `__init__`, it will not be called in this situation, and for that reason, sub-modules should not have `__init__` methods. If this is required, then all initalisation for sub-modules should be done by the top-level module's (i.e. `foo`'s) `__init__` method. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'examples/usercmodule/cppexample/examplemodule.c')
0 files changed, 0 insertions, 0 deletions