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
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 | s = str(val) # or s = unicode(val) |
Send key presses | type(":lineEdit_Widget", "Orange") |
Native boolean values | True, False |
JavaScript
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 |
Perl
Feature | Perl |
---|---|
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 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 |
Ruby
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 |
Tcl
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 |
macOS Bindings
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 |
© 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.