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
ToString
New
Delete
Len
ReadTextFile
WriteTextFile
SelectFiles
SelectFolder
ListFiles
DeleteFile

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

CurrentScript
Assert
Throw
DebuggerEnabled
Object Members: obj.Find
obj.Split
obj.Join
obj.Upper
obj.Lower
obj.Sub
obj.Strip
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.Date
obj.Time
obj.DateTime
obj.Timestamp
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:

String ToString([items, ...]);

Converts all the arguments to strings.

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

string obj.Strip([delimiters]);

Strips the specified characters off the start and end of the string.

Arguments:
Returns:
Example:
c = "[A string]";
Print(c.Strip("[]"), "\n");
A String

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:

int Len(object[, object2]);

Returns the length of an array or hashtable. If more than one object is passed it'll sum the length of all of them. Non collection objects count as 1 thing. For instance a integer or floating point value are "1" item.

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:

void SelectFiles(ParentWnd, Callback[, FileTypes[, InitialDir[, MultiSelect[, SaveAs]]]]);

Shows a file select dialog.

Arguments:
Returns: Nothing.

Example:
function OnFiles(files)
{
    Print("Files:", files, "\n");
}
				
SelectFiles(Parent, "OnFiles", "*.png", "C:\\Users\\myUserName\\Desktop", 1);
C:\Users\myUserName\Desktop\2channel.png
C:\Users\myUserName\Desktop\19.Poster_1.png
C:\Users\myUserName\Desktop\payment.png

void SelectFolder(ParentWnd, Callback[, InitialDir]);

Shows a folder select dialog.

Arguments:
Returns: nothing.

Example:
function OnFolder(folder)
{
    Print("Folder:", folder, "\n");
}
				
SelectFolder(Parent, "OnFolder", "C:\\Users\\myUserName\\Desktop");

list ListFiles(folder_path[, pattern]);

Lists files in a folder.

Arguments:
Returns:

bool DeleteFile(path);

Deletes a file.

Arguments:
Returns:

string CurrentScript();

Returns:

bool Assert(value[, msg]);

Checks that 'value' is non-zero, if it is zero, it throws an exception with 'msg' if supplied.

Arguments:
Returns:

void Throw([msg]);

Throws an exception, optionally with 'msg' as the message.

Arguments:
Returns:

void DebuggerEnabled(enabled);

Turns the debugger on or off.

Arguments:
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. Typically this follows creating a file object with New and once the file operations are done, use Delete to clean up the memory.

Also of note: to get or change the size of the file use the Length member.

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.

int64 obj.Timestamp;

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

string 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.

string 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.

string 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).

string ColourSpaceToString(intColourSpace);

Converts a LColourSpace integer to a string.

int StringToColourSpace(stringColourSpace);

Converts a string colour space representation to a LColourSpace.

Returns:

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 LColourSpace 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:

void GetInputDlg(parent_wnd, initial_value, msg, title, is_password, callback);

Asks the user for input using a dialog.

Arguments:
Returns: Nothing.

function MyCallback(str)
{
    Print("String entered is: '" + str + "'\n");
}

GetInputDlg(app, "SomeText", "Enter some text:", "InputTest", false, "MyCallback");

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