Skip to content

Adding a language to Waterbear (old way)

Dethe Elza edited this page Jan 16, 2015 · 2 revisions

OUTDATED: This page needs to be updated and does not reflect the current state of Waterbear.


To add a new language wrapper to waterbear, the following files and methods must be added:

In the following file names, replace "language" with your language name.

1. In the template directory, template/:


language.examples
language.stage

language.examples can be empty but must be present and contains a list of example scripts from the examples/language/ folder

language.stage can be based off of either javascript.stage or arduino.stage, depending on whether the language can run in the browser or not. Puts different bits in place like the preview panel and the script text output panel.

2. In your language's directory, languages/language:


language.js
language_runtime.js

language.js This is where you put code specific to the IDE and your language, but not specific to the individual blocks. You will need to implement the functions wb.wrap(script), wb.runCurrentScripts(force), and wb.clearStage() [as a no-op if there is no stage needed] as well as defining the base wb.choiceLists here.

language_runtime.js contains utility functions for your scripts, if the scripts run in the browser. This file is not necessary if running a script in the browser is not supported.

The block-specific code also goes in languages/language. Each block menu has up to four files associated with it:


menuname.js
menuname_runtime.js
menuname.css
menuname.json

menuname.js provides IDE-support for the menu, such as additions to wb.choiceLists. This is an optional file. menuname_runtime.js provides utility functions for running scripts, if running in the browser is supported. This is an optional file. menuname.css This specifies the color of each block in the menu. menuname.json provides rules for building the blocks. This is where all the blocks of the language are actually defined. For script templates, if you find them getting too long, add a helper function in the _runtime and call it from the script template.

4. In bin/build:

You will need to add an entry to the plugins, pluginLibs, styles, and libs objects for your language. This will allow your language to be built and the files to get concatenated. Files are added in the order specified, so you can choose the order of the menu. Where a base language file (language.js) is used, put it first so subsequent files can count on the functions in it being defined.