Menu

Hello World

Purpose

The purpose of this guide is to provide an example of using Aussom-Script in the browser.

Aussom-Script Hello World

Below is an example of the simplist aussom-script hello world application. There are 3 key things that need to be present to use aussom-script and I'm going to detail them below the example.

<!DOCTYPE html>
<html>
  <head>
    <title>Aussom Test</title>

    <!-- Need to first include aussom-script.js, this is the only dependency. -->
    <script type="text/javascript" charset="utf-8" src="aussom-script.js"></script>

    <!-- Create a new script section with type "text/aussom-script" to
    define your Aussom application code. -->
    <script type="text/aussom-script" charset="utf-8">
class AussomTest {
  public main(args) {
    // Log to console.
    c.info("Hello, Aussom!");
  }
}
    </script>
  </head>
  <!-- We need to call the main() Javascript function which runs
  the Aussom interpreter. -->
  <body onload="main()">
    <!-- Add HTML here -->
  </body>
</html>

Include aussom-script.js

The Aussom interpreter is added to the page using this Javascript include. Without this included script file there will be no Aussom interpreter to run your code, so make sure it's there.

<script type="text/javascript" charset="utf-8" src="aussom-script.js"></script>

Define your aussom-script code

There are two ways to define your aussom-script code, but both require the <script> tag. You an add the script within the tag, or with the src attribute as a remote file. If you define it with the src attribute, it must be served from a web server or you will get a CORS error. The include mechanism uses XMLHttpRequest so it's subject to CORS protection.

<script type="text/aussom-script" charset="utf-8">
class AussomTest {
  public main(args) {
    // Log to console.
    c.info("Hello, Aussom!");
  }
}
</script>

Run the interpreter onload

In the body tag, we need to set the onload to run the main() function of the interpreter. This will kick off the aussom-script interpreter to look for Aussom script sections with code and to load remote resources. It then looks for the aussom-script main function which we defined in our AussomTest class and it executes it. Note that you can name the class whatever you want, in this example we use AussomTest but you can make it MyClass or whatever you like. The interpreter is looking for the main function in any class, so it's important that you only supply one main function in your code.

<body onload="main()">

Run it!

That's it, those three things is all you need. Save the HTML file and double click it to run in your web browser. In this example we don't manipulate the dom, so nothing will change on the screen. Open up the developer tools in the browser and check the console output and you should see Hello, Aussom! in the output.