Lgi Scripting Library

These are the built in methods for the Lgi scripting language:
Strings Containers File System Dates and Time Bitmaps User Interface General
Global functions: LoadString
FormatSize
Sprintf
Print
New
Delete
ReadTextFile
WriteTextFile
SelectFiles
ListFiles
DeleteFile

PathExists
PathJoin
PathSep
Sleep
ClockTick
Now
CreateSurface
LoadDialog
MessageDlg
GetInputDlg
GetViewById
Execute
System
OsName
OsVersion

CurrentScript
Object Members: obj.Find
obj.Split
obj.Join
obj.Upper
obj.Lower
obj.Sub
obj.Add
obj.HasKey
obj.Delete
obj.Sort
obj.Open
obj.Read
obj.Write
obj.Pos
obj.Close
obj.Year
obj.Month
obj.Day
obj.Hour
obj.Minute
obj.Second
obj.Milli
obj.Int

obj.Date
obj.Time
obj.DateTime
obj.x
obj.y
obj.Bits
obj.ColourSpace
obj.Palette
obj.Load
obj.Save
obj.Handle
obj.Id
obj.Name
obj.Value
obj.Enabled
obj.Foreground
obj.Background
obj.Type
obj.Length

string LoadString(id);

Loads a string from the resource file. The strings have to be stored in a Lgi resource file and loaded at runtime by the current application. There is a graphical editor for the resource files.

Arguments:
Returns:
Example:
c = LoadString(186);
Print(c, "\n");
Enter offset:

string FormatSize(bytes);

Formats a number of bytes in KB, MB or GB as appropriate.

Arguments:
Returns:
Example:
c = FormatSize(345674211);
Print(c, "\n");
329.66 M

string Sprintf(format[, args, ...]);

Formats a string. Not available on the mac platform.

Arguments:
Returns:
Example:
c = Sprintf("Format: %i, %i, %s, 0x%x\n", 345, 11, "StringArg", 0x1234fa);
Print(c);
Format: 345, 11, StringArg, 0x1234af

void Print(item1[, item2, ...]);

Prints variables on the console, if available. No new line is explicitly printed, you have to add "\n" to your arguments to move to the next line.

Arguments:
Returns:

int obj.Find(sub_string[, start[, end]]);

Finds a the position of a sub-string.

Arguments:
Returns:
Example:
c = "A string to search";
Print(c.Find("to"), "\n");
Print(c.Find("missing"), "\n");
9
-1

list obj.Split(separator[, max_split]);

Splits a string into parts based on a separator.

Arguments:
Returns:
Example:
c = "123, 456, 879";
p = c.split(",");
for (i=0; i<p.Length; i++)
{
    Print("[", i, "]='", p[i].Strip(), "'\n");
}
[0]='123'
[1]='456'
[2]='879'

string obj.Join(list);

Joins a list of objects into a single string separated by the 'obj' string.

Arguments:
Returns:
Example:
c = New("list");
c.Add(123);
c.Add(456);
c.Add(789);
p = ", ";
r = p.Join(c);
Print(r, "\n");
123, 456, 789

string obj.Upper();

Makes an upper case version of 'obj'.

Returns:
Example:
c = "A string";
Print(c.Upper(), "\n");
A STRING

string obj.Lower();

Makes a lower case version of 'obj'.

Returns:
Example:
c = "A string";
Print(c.Lower(), "\n");
a string

string obj.Sub(start[, end]);

Returns part of the string 'obj'.

Arguments:
Returns:
Example:
c = "A string";
Print(c.Sub(2, 5), "\n");
Print(c.Sub(4), "\n");
str
ring

object New(object);

Creates a new object.

Arguments:
Returns:
Example:
c = New("DateTime");
c.Date = "1/4/2014";
Print(c.Type(), ": ", c, "\n");
DateTime: 1/04/2014 12:00:00a

void Delete(object);

Will set any object to NULL. Must be used with custom types before they go out of scope otherwise they will leak memory. But also works on any other type of object, like lists, hashtables or basic strings and ints.

Arguments:
Returns:

void obj.Add(object[, key]);

Adds 'object1' to a container. Depending on the object type:
Arguments:
Returns:
Example:
c = New("list");
c.Add("first");
c.Add("second");
Print(c, "\n");
Print(c.Length, "\n");
{first, second}
2

bool obj.HasKey(key);

Returns true of the container has something stored at 'key':
Arguments:
Returns:
Example:
c = New("hashtable");
c.Add(23, "first");
c.Add(345, "second");
Print(c.HasKey("asd"), "\n");
Print(c.HasKey("first"), "\n");
0
1

void obj.Delete(key);

Removes and deletes an object from the container

Arguments:
Returns:
Example:
c = New("hashtable");
c.Add(123, "first");
c.Add(456, "second");
Print(c.Length, "\n");
c.Delete("first");
Print(c.Length, "\n");
2
1

void obj.Sort(key);

Sorts a list. Not relevant for a HashTable.

Arguments:
Returns:
Example:
c = New("list");
c.Add("first");
c.Add("second");
c.Sort();

string ReadTextFile(filename);

Returns the contents of a text file.

Arguments:
Returns:

bool WriteTextFile(filename, data);

Writes the contents of a variable to a text file.

Arguments:
Returns:

list SelectFiles(parent_wnd[, file_types[, initial_dir[, multi_select]]]);

Shows a file select dialog.

Arguments:
Returns:
Example:
files = SelectFiles(Parent, "*.png", "C:\\Users\\matthew\\Desktop", 1);
if (files)
{
    for (i=0; i<files.Length; i++)
    {
        Print(files[i], "\n");
    }
}
C:\Users\matthew\Desktop\2channel.png
C:\Users\matthew\Desktop\19.Poster_1.png
C:\Users\matthew\Desktop\payment.png

list ListFiles(folder_path[, pattern]);

Lists files in a folder.

Arguments:
Returns:

bool DeleteFile(path);

Deletes a file.

Arguments:
Returns:

string CurrentScript();

Returns:

int PathExists(path);

Queries the file system to see if a path exists as a file or folder.

Arguments:
Returns:

string PathJoin(path1[, path2[, ...]]);

Joins a whole lot of path fragments together, evaluating relative parts as needed.

Arguments:
Returns:

string PathSep();

Returns:

bool obj.Open(path[, mode]);

Opens a file.

Arguments:
Returns:

object obj.Read(length[, type]);

Reads content from a file at the current location.

Arguments:
Returns:

int obj.Write(object[, length]);

Writes the object to the file.

Arguments:
Returns:

int obj.Pos([new_position]);

Gets or sets the current file position.

Arguments:
Returns:

void obj.Close();

Closes a file.

Returns:

void Sleep(ms);

Pauses the current thread.

Arguments:
Returns:

int64 ClockTick();

Returns the current clock tick.

Arguments:
Returns:

datetime Now();

Returns the current date time.

Arguments:
Returns:

int obj.Year;

Sets or gets the year part of a date/time object.

int obj.Month;

Sets or gets the month part of a date/time object.

int obj.Day;

Sets or gets the day part of a date/time object.

int obj.Hour;

Sets or gets the hour part of a date/time object.

int obj.Minute;

Sets or gets the minute part of a date/time object.

int obj.Second;

Sets or gets the second part of a date/time object.

int obj.Milli;

Sets or gets the millisecond part of a date/time object.

int obj.DateInt64;

Sets or gets the int64 version of a date/time object. This is compatible with a range of operating system APIs.

int obj.Date;

Sets or gets the date part of the object. Typically this is in the form 'day/month/year' in the current locale of the operating system.

int obj.Time;

Sets or gets the time part of the object. Typically this is in the form 'hour:minute:second' in the current locale of the operating system.

int obj.DateTime;

Sets or gets both the date and time parts of the object as a string.

object CreateSurface(x, y[, pixel_type]);

Creates a bitmap in memory with the specified dimensions and bit depth or colour space.

Arguments:
Returns:
Example:
c = CreateBitmap(320, 240);
Print(c.Type(), ": ", c.x, ", ", c.y, ", ", c.Bits, ", ", c.ColourSpace, "\n");
Surface: 320, 240, 32, 1211639896
The colourspace '1211639896' decimal is '0x48382858' in hex. Each byte is a component description, the high nibble is the colour type (defined in Lgi as the GComponentType enum), and the lower nibble is the number of bits (and zero = 16 bits).

int obj.X;

The width of the image in pixels (read only).

int obj.Y;

The height of the image in pixels (read only).

int obj.Bits;

The number of bits per pixel (read only).

colour_space obj.ColourSpace;

The colour space of the image (read only). This is a integer value that maps to a GColourSpace enum.

list obj.Palette;

The palette of the image. Use array indexing to set or get the individual palette entries.

bool obj.Load(filename);

Loads an image from a file. Only filters that are compiled into the executable are supported.

Arguments:
Returns:

bool obj.Save(filename);

Soads an image to a file. Only filters that are compiled into the executable are supported.

Arguments:
Returns:

view LoadDialog(parent_wnd, dialog_id);

Loads a dialog from a resource file.

Arguments:
Returns:

string MessageDlg(parent_wnd, msg, title, btns);

Displays a model alert message.

Arguments:
Returns:

string GetInputDlg(parent_wnd, initial_value, msg, title, is_password);

Asks the user for input using a dialog.

Arguments:
Returns:

object GetViewById(parent, id);

Gets the child view by it's id.

Arguments:
Returns:

int obj.Handle;

The operating system handle for the view (read only).

int obj.Id;

The control ID for the view.

string obj.Name;

The textual name assocaited with the view.

int64 obj.Value;

The numerical value assocaited with the view.

bool obj.Enabled;

This sets or gets the enabled/disable state of the view.

colour obj.Foreground;

Gets or sets the CSS foreground colour for the view.

colour obj.Background;

Gets or sets the CSS background colour for the view.

string Execute(executable[, arguments]);

Executes a process and waits for it to finish.

Arguments:
Returns:

bool System(executable[, arguments]);

Executes a process and doesn't wait for it to finish.

Arguments:
Returns:

string OsName();

Returns the current OS name:
Example:
Print(OsName(), "\n");
Win64

list OsVersion();

Returns the current OS version as 3 integers in a list.

Returns: The OS version:
Windows XP {5, 1, 0}
Windows Vista {6, 0, 0}
Windows 7 {6, 1, 0}
Windows 8 {6, 2, 0}
Mac OS X 10.8.2 {10, 8, 2}
Ubuntu 13.04 {3, 8, 8} (i.e. the kernel version)

Example:
Print(OsVersion(), "\n");
{6, 1, 0}

string obj.Type;

Gets the type of the object as a string.

Returns:
Example:
c = New("list");
Print(c.Type(), "\n");
List

int obj.Length;

Gets the length of an object. The meaning of that depends on the context of what type it is:
Returns:
Example:
c = "This is a string.";
Print(c.Length, "\n");

c = New("list");
c.Add(123);
c.Add(456);
Print(c.Length, "\n");
17
2