Creating a library, using Jaguar #1133
davidg238
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
Thanks for the updated version. A few minor suggestions:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The original post on creating a Toit Library was written a year ago, when Toit was only offered as closed source. Since then, the Toit language has been open sourced and Jaguar tooling added. What follows is an update of the original article, to reflect the usage of Jaguar v1.7.1, to revise and run the project FW_Keyboard.
Refering to the repository FW_Keyboard
The core code layout looks like :
In the project root directory:
To create the (empty) package.yaml and package.lock files run
jag pkg init
There is no response to this command.
To declare the external dependencies of the library src code, run
jag pkg install github.com/toitware/toit-color-tft
the response is
Info: Package 'github.com/toitware/toit-color-tft@1.3.0' installed with name 'color_tft'
then run
jag pkg install github.com/toitware/toit-pixel-display
the response is
Info: Package 'github.com/toitware/toit-pixel-display@1.6.0' installed with name 'pixel_display'
then run
jag pkg install github.com/toitware/toit-pixel-strip
the response is
Info: Package 'github.com/toitware/toit-pixel-strip@0.2.0' installed with name 'pixel_strip'
If the library is to be shared, edit package.yaml adding a
name:
anddescription:
entry.package.yaml then looks like:
The named dependencies
color_tft
andpixel_display
correspond to the imports in the library src, so for example in the src/keyboard_driver.toit file:In the src directory:
jag pkg
actions are required.External library dependencies are already captured in the project root package.yaml file.
To make your library easier to use, make a file matching the library name, like
fw_keyboard.toit
, contents:Note, the contents of the source directory are exported.
Dependencies between files in the library, are by relative import.
For example, in keyboard_driver.toit, the
BBQ10Keyboard
class is imported as:import .bbq10keyboard show BBQ10Keyboard
In the tests directory:
The tests directory contains code meant to test your library and would not be called by other developers. As application code, a package.lock file is required and is specific to the directory.
To create a package.lock, run
jag pkg init
To populate the dependencies, run
jag pkg install --local --name fw_keyboard ..
the response is
Info: Package '..' installed with name 'fw_keyboard'
then run
jag pkg install github.com/toitware/toit-color-tft
jag pkg install github.com/toitware/toit-pixel-display
jag pkg install github.com/toitware/toit-pixel-strip
Dependency to the library code under construction is declared in the first install, the name is explicit.
Dependencies to external libraries is declared in the succeeding installs.
The package.yaml in the tests directory now looks like:
jag run fw_display_test.toit
In the examples directory:
To create a package.lock, run
jag pkg init
To populate the dependencies, run
jag pkg install --local --name fw_keyboard ..
jag pkg install toit-font-google-100dpi-roboto
jag pkg install github.com/toitware/toit-color-tft
jag pkg install github.com/toitware/toit-pixel-display
jag pkg install github.com/toitware/toit-pixel-strip
From the example directory, run the example:
jag run demo.toit
Add a
.gitignore
file in the project root directory, as the (hidden) package directories must not versioned into the repository. Looks like:The final library code structure looks like:
Beta Was this translation helpful? Give feedback.
All reactions