Seed Native Functions

Introduction

There are a number of functions in Seed that are not in the JavaScript language which have been created so they can be used in desktop applications. This section deals with the ones that will commonly used.

print

This was encountered in the Hello World example. The purpose of this to output the string supplied with this command to the console. The format of it as follows:

print (string);

i.e.

print ("This is a test string");

It can only take one string at a time and if any other are given, it comes up with the following error message.

ArgumentError print expected 1 argument, got 2

If you wanted to display more than one string on, than you would join them using the + operator. An example of this is as follows:

print ("Hello" + " " + "world");

As mentioned, print displays the string supplied with it. If you supply another type of variable like an integer, it will automatically convert it to a string and display it. This can be seen as:

print (42);
print (true);
print (42.33);

For info, print and Seed.print are the same functions.

Seed.Argv

To use command line arguments, use the Seed.argv command. This contains an array of the command line arguments used when running the program. In this array, it will include the seed command, the program name and command line arguments. The first argument will always be stored in Seed.argv[2].

Seed.sprintf

Seed.sprintf is similar to printf (or Seed.printf) but is more versatile as it allows you to display variables with the string you want to display on console. This is done by putting format specifiers in the string. The basic format specifiers are as follows:

Another facility of sprintf is that you can format the output of the data.

In this example, you can specify the number of decimal points that can be displayed when displaying a float variable:

Seed.sprintf ("%.2f", 3.1543);

The output is:

3.15

Contrast this with the ordinary printf statement:

print (3.1543);

which outputs:

3.1543

You can also right align text by padding it with spaces for better visual output. This means that if you used multiple format specifiers in the string, you can have them the same width. An example of this would be if you had string that is 4 characters long you can specify it output it with a width of 6 which would add two spaces in front of this. To do this, insert a number in the format specifier which is the size of the width you want the output to be.