12345678Build a ball pit · Step 1 of 8
Run your first app
You'll learn
- Run a script with
datumhue run - Reload on save with
--watch - Find where errors show
- Time
- 5 min
- File
hello.lua
An app is a Lua script. In this step you write one that says hello, run it, change it while it runs, and break it on purpose to see where errors show.
Hello world
Make a folder for this tutorial. In it, save this as hello.lua:
local screen = datumhue.ui.root:panel({
width = "100%",
height = "100%",
justify_content = "center",
align_items = "center",
})
screen:label({ text = "Hello, DatumHue!", font_size = 48 })
In this example: datumhue.ui.root UiElement:panel UiElement:label
datumhue.ui.rootis the area your app shows things in: here, the whole window.UiElement:paneladds a box to it. This one fills the window and centers what it holds, so the text stays in the middle at any window size.UiElement:labelputs a line of text in the panel. The text takes its color and font from the theme, so it reads on a light or a dark one.
Run it
Open a terminal in the folder and run the script:
$ datumhue run hello.lua
A window opens with your greeting in the middle. The script runs once, top to bottom, as the app starts. What it builds stays on screen until you close the window.
Change it while it runs
Close the window, then run the script again with --watch:
$ datumhue run --watch hello.lua
Now every save runs your app again from the new source. Change the greeting, save, and the window shows it. A save that does not compile leaves the running version alone and prints the error.
Images, sounds and scenes your app loaded change in place when their
files do, without a restart. Keep a --watch run going while you follow
this tutorial.
When something goes wrong
Break the program on purpose: change font_size to font_sise and save.
The text disappears, and the terminal says why. It prints a line saying
your app crashed, with the reason: unknown key 'font_sise', followed by
the keys a label does take.
An error your code does not catch ends your app. With --watch the window
stays open: fix the line, save, and your app runs again. Without it,
DatumHue closes along with your app.
Mistyped Lua, such as a bracket left open, is caught before the app starts, and the message names the line. When a callback errors shows how to catch errors yourself.
Try this
- Change the greeting to your own name while
--watchruns. - Add a second label to the panel. Where does it go? Then add
flex_direction = "column"to the panel and save again. - Delete
font_sizeand see which size the theme picks.
Recap
- An app is a Lua script, and
datumhue runruns it. The script body runs once, as the app starts. --watchruns your app again on every save.- Errors show in the terminal you ran from. An error your code does not catch ends the app.
New in this step