Equivalent Script API

Squish provides the same fundamental APIs in all the scripting languages it supports, plus some extra language-specific features where required, such as file handling in JavaScript because it 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.

The differences are described in language-specific notes. For example, the Python Notes show how to access Python's built-in type function instead of Squish's type(objectOrName, text) function the JavaScript Notes and Extension APIs describe the additional APIs Squish makes available for file handling, interacting with the operating system, using XML, and using SQL, for example.

Sample Class

Before reviewing the differences, we take a look at the sample class that is used in the tables below.

For non-macOS platforms the tables use 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 tables use the 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 tables also assume the existence of an object of type C called c.

The underscores in some of the calls in the tables relate to Objective C. See Functions and Properties (macOS) for details.

Equivalent Script Functions

The following tables provide 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 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.

The Squish API documentation contains examples (almost always in all the supported scripting languages} and links to examples elsewhere in the manual. If an example is not shown in your scripting language, use the tables below to convert from one of the languages shown to the language you want.

Python

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

JavaScript

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

Perl

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

Ruby

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

Tcl

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

macOS Bindings

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

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Search Results