Squish provides the same fundamental APIs in all the scripting languages it supports, plus some extra language-specific features where required (e.g., file handling in JavaScript since this isn't provided by the standard language). In this section we will discuss how the APIs are used, noting the usage differences that are due to differences between the scripting languages themselves.
But before reviewing the differences, we will first look at the sample class that is used in the table that follows.
For non-macOS platforms the table uses the following example C++ class:
class C { public: C(); C(const char *s); void doA(bool b); static void doB(); int p; ... };
For macOS the table uses following Objective-C class:
@interface C : NSObject { ... } - (void)doA; - (void)doB:(BOOL)b; + (void)doC; + (void)doD:(BOOL)b; - (int)p; - (void)setP:(int)newP; ... @end
The table also assumes the existence of an object of type C
called c
.
The following table provides a brief overview of the equivalent script functions for the most basic tasks such as creating an object, getting and setting a property, and performing comparisons. Although the actions performed on each row are the same and use the same APIs, the actual example code differs because of the syntactic and structural differences between the scripting languages that Squish supports.
Feature | Python |
---|---|
Construct a default object | c = C() |
Construct an object using an argument | c = C("apple") |
Get property p 's value | x = c.p |
Set property p 's value | c.p = 10 |
Call a member function | c.doA(True) |
Verify equality | test.compare(c.p, 2) |
Compare a wrapped string-like object with a native string | s == "Orange" |
Convert to a native string |
|
Send key presses | type(":lineEdit_Widget", "Orange") |
Native boolean values | True, False |
Feature | JavaScript |
---|---|
Construct a default object | var c = new C(); |
Construct an object using an argument | var c = new C("apple"); |
Get property p 's value | var x = c.p; |
Set property p 's value | c.p = 10; |
Call a member function | c.doA(true); |
Verify equality | test.compare(c.p, 2); |
Compare a wrapped string-like object with a native string | s == "Orange" |
Convert to a native string | var s = String(val); |
Send key presses | type(":lineEdit_Widget", "Orange"); |
Native boolean values | true, false |
Feature | Perl |
---|---|
Construct a default object |
|
Construct an object using an argument |
|
Get property p 's value | my $x = $c->p; |
Set property p 's value | $c->p(10); |
Call a member function | $c->doA(1); |
Verify equality | test::compare($c->p, 2); |
Compare a wrapped string-like object with a native string | $s eq "Orange" |
Convert to a native string | my $s = "" . $val; |
Send key presses | type(":lineEdit_Widget", "Orange"); |
Native boolean values | 1, 0 |
Feature | Ruby |
---|---|
Construct a default object | c = C.new |
Construct an object using an argument | c = C.new("apple") |
Get property p 's value | x = c.p |
Set property p 's value | c.p = 10 |
Call a member function | c.doA(true) |
Verify equality | Test.compare(c.p, 2) |
Compare a wrapped string-like object with a native string | s == "Orange" |
Convert to a native string | s = String(val) |
Send key presses | type(":lineEdit_Widget", "Orange") |
Native boolean values | true, false |
Feature | Tcl |
---|---|
Construct a default object | set c [construct C] |
Construct an object using an argument | set c [construct C "apple"] |
Get property p 's value | set x [property get $c p] |
Set property p 's value | property set $c p 10 |
Call a member function | invoke $c doA true |
Verify equality | test compare [property get $c p] 2 |
Compare a wrapped string-like object with a native string | compare $s "Orange" |
Convert to a native string | set s [toString $val] |
Send key presses | invoke type ":lineEdit_Widget" "Orange" |
Native boolean values | true, false |
There are also language-specific notes further on in the manual. For
example, the Python Notes (Section 6.14) show how to access Python's
built-in type
function instead of Squish's type
function, and the JavaScript Notes and Extension APIs (Section 6.16)
describe the additional APIs Squish makes available—for example,
for file handling, interacting with the operating system, using XML, and
using SQL.
For macOS, here are the bindings specific to Objective-C objects:
Feature | Python | JavaScript | Perl | Ruby | Tcl |
---|---|---|---|---|---|
Call a member function (without arguments) | c.doA() | c.doA(); | $c->doA(); | c.doA() | invoke $c doA |
Call a member function (with arguments) | c.doB_(True) | c.doB_(true); | $c->doB_(1); | c.doB_(true) | invoke $c doB_ true |
Call a class (static) function (without arguments) | C.doC() | C.doC(); | C::doC(); | C.doC() | invoke C doC |
Call a class (static) function (with arguments) | C.doD_(True) | C.doD_(true); | C::doD_(1); | C.doD_(true) | invoke C doD_ true |
Note that the underscores shown in some of the calls shown in the table relate to Objective C; see Functions and Properties (macOS) (Section 6.3.2) for details.
Squish's APIs are described in the following sections. Some are shown with examples (almost always in all the supported scripting languages), and some of the descriptions have links to examples elsewhere in the manual. For the rare cases where an example is not shown in the scripting language you want to use, the above table should make it easy to convert from one of the languages shown to the language you want.