Application scripting
We want to make it easy for users to create their own applications, so we allow them to write the application logic as scripts. Currently, we use the #link(“https://berry-lang.github.io/”)[Berry scripting language]. It is an Object Oriented language that claims to require only four kilobytes of RAM.
All the widgets with which the scripts can interact have an associated object in the scripting runtime. These objects are created before interpreting any scripts. The script for the user interface of the @fig-to-do-list-app has access to the text field, the button, the checkboxes, and the item text. The objects provide methods that execute native code to modify and query the state of the widgets. For example, a script can retrieve the content of a text field, change the content of a text, toggle a checkbox, etc.
To make these objects more accessible from the user script, each object associated with a static widget has a name. In the @fig-to-do-list-app, only the text field and the button are static. The checkboxes and item texts are not static because they are dynamically created. To get access to them the dynamic container is named and has an associated object. It allows traversing the list of items.
On the user script side, we use a callback-based approach to setup the widgets’ reactions. For example, the script for user interface of the @fig-to-do-list-app could attach an on-click callback to a button. The host executes this callback when it processes a click event coming from the corresponding button.
For example, the following script attach a callback to the button named ADD_ITEM.
Upon click on this button, the callback retrieve the content of the text field named ITEM_TEXT, call a function create_new_item that create a new item and add it to the to-do list.
ADD_ITEM.on_click = def()
var todo_item = ITEM_TEXT.get_text()
create_new_item(todo_item)
end
Currently a single script is used to describe the application logic.
In the future we plan to explore the idea of attaching a script to every widget that the user can interact with.
For example, the following script could be directly attached to the SEARCH button:
def on_click()
var todo_item = ITEM_TEXT.get_text()
create_new_item(todo_item)
end
To reduce the cost of instantiating an object for every widget that the script can interact with, we could instantiate objects on-demand. So only widget that the script interacts with will have a corresponding objects in the scripting runtime.