6.2. Equivalent Script API

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

FeaturePython
Construct a default objectc = C()
Construct an object using an argumentc = C("apple")
Get property p's valuex = c.p
Set property p's valuec.p = 10
Call a member functionc.doA(True)
Verify equalitytest.compare(c.p, 2)
Compare a wrapped string-like object with a native strings == "Orange"
Convert to a native string

s = str(val) # or

s = unicode(val)

Send key pressestype(":lineEdit_Widget", "Orange")
Native boolean valuesTrue, False
FeatureJavaScript
Construct a default objectvar c = new C();
Construct an object using an argumentvar c = new C("apple");
Get property p's valuevar x = c.p;
Set property p's valuec.p = 10;
Call a member functionc.doA(true);
Verify equalitytest.compare(c.p, 2);
Compare a wrapped string-like object with a native strings == "Orange"
Convert to a native stringvar s = String(val);
Send key pressestype(":lineEdit_Widget", "Orange");
Native boolean valuestrue, false
FeaturePerl
Construct a default object

my $c = new C();  # new-style

my $c = C->new(); # old-style

Construct an object using an argument

my $c = new C("apple");  # new-style

my $c = C->new("apple"); # old-style

Get property p's valuemy $x = $c->p;
Set property p's value$c->p(10);
Call a member function$c->doA(1);
Verify equalitytest::compare($c->p, 2);
Compare a wrapped string-like object with a native string$s eq "Orange"
Convert to a native stringmy $s = "" . $val;
Send key pressestype(":lineEdit_Widget", "Orange");
Native boolean values1, 0
FeatureRuby
Construct a default objectc = C.new
Construct an object using an argumentc = C.new("apple")
Get property p's valuex = c.p
Set property p's valuec.p = 10
Call a member functionc.doA(true)
Verify equalityTest.compare(c.p, 2)
Compare a wrapped string-like object with a native strings == "Orange"
Convert to a native strings = String(val)
Send key pressestype(":lineEdit_Widget", "Orange")
Native boolean valuestrue, false
FeatureTcl
Construct a default objectset c [construct C]
Construct an object using an argumentset c [construct C "apple"]
Get property p's valueset x [property get $c p]
Set property p's valueproperty set $c p 10
Call a member functioninvoke $c doA true
Verify equalitytest compare [property get $c p] 2
Compare a wrapped string-like object with a native stringcompare $s "Orange"
Convert to a native stringset s [toString $val]
Send key pressesinvoke type ":lineEdit_Widget" "Orange"
Native boolean valuestrue, 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:

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