This is the original reference for "freewheeling apps".
THJX6RCJEMADQ3O6UOXA5DMGVGHMVKZHG4U7IUEV5E75FC3XRHXQC # Some useful building blocks
# Building blocks for your Freewheeling AppsFreewheeling apps consist of 4 kinds of things:- a small number of functions you can define that get automatically calledfor you as appropriate,- a wide variety of primitives that you can call but not modify,- tests that start with `test_` and run on startup or after any change youmake to the app's code, and- any other function you can define and call at will.
Apps can be composed of a wide variety of building blocks that youcan use in your functions, including a small number of functions that getautomatically called for you as appropriate.
The rest of this document will summarize what is available to you in the firsttwo categories.
## Functions that get automatically called* `App.initialize_globals()` -- called before running each test and alsobefore the app starts up. As the name suggests, use this to initialize allyour global variables to something consistent. I also find it useful to beable to see all my global variables in one place, and avoid definingtop-level variables anywhere else (unless they're constants and never goingto be modified).
## Functions you can implement that will get automatically called
* `App.initialize(arg)` -- called when app starts up after`App.initialize_globals`. Provides in `arg` an array of words typed in ifyou ran it from a terminal window.
* `on.initialize(arg)` -- called when app starts up. Provides in `arg` anarray of words typed in if you ran it from a terminal window.
* `App.focus(start?)` -- called when the app starts or stops receiving
* `on.save_settings()` -- called after on.quit and should return a table whichwill be saved to disk.* `on.load_settings(settings)` -- called when app starts up, before`on.initialize`. Provides in `settings` the table that was saved to disk thelast time the app shut down.* `on.focus(start?)` -- called when the app starts or stops receiving
* `App.draw()` -- called to draw on the window, around 30 times a second.
* `on.code_change()` -- called when you make changes to the app using[driver.love](https://git.sr.ht/~akkartik/driver.love), any time you hit`f4` inside driver.love, after a definition is created or modified.* `on.draw()` -- called to draw on the window, around 30 times a second.
* `App.mousepressed(x,y, mouse_button)` -- called when you press down on amouse button. Provides in `x` and `y` the point on the screen at which theclick occurred, and in `mouse_button` an integer id of the mouse buttonpressed.
* `on.mouse_press(x,y, mouse_button)` -- called when you press down on a mousebutton. Provides in `x` and `y` the point on the screen at which the clickoccurred, and in `mouse_button` an integer id of the mouse button pressed.
* `App.wheelmoved(dx,dy)` -- called when you use the scroll wheel on a mousethat has it. Provides in `dx` and `dy` an indication of how fast the wheelis being scrolled. Positive values for `dx` indicate movement to the right.Positive values for `dy` indicate upward movement.
* `on.mouse_wheel_move(dx,dy)` -- called when you use the scroll wheel on amouse that has it. Provides in `dx` and `dy` an indication of how fast thewheel is being scrolled. Positive values for `dx` indicate movement to theright. Positive values for `dy` indicate upward movement.