berry-lang / berry

A ultra-lightweight embedded scripting language optimized for microcontrollers.
https://berry-lang.github.io
MIT License
782 stars 95 forks source link

Loading / importing an external script #395

Closed max22- closed 4 months ago

max22- commented 4 months ago

Hello, i've searched through the documentation but i haven't found a way to import a script from another one. what is the best way to do it ? the current workaround i am using is this :

class MyClass
end
compile('myclass.be', 'file')()

I have to create an empty class with the same name as the one i am importing otherwise i get a syntax error. Is there an equivalent of python 'import' that i am missing ?

Thank you, Maxime

s-hadinger commented 4 months ago

There are basically two ways:

See here: https://github.com/berry-lang/berry/wiki/Chapter-8#83-how-to-package-a-module

max22- commented 4 months ago

ok ! thank you very much !