StaticScript is a statically typed programming language, syntactically like TypeScript.
English | 简体中文
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-ubuntu.sh)"
Or
wget https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-ubuntu.sh
sudo chmod +x install-ubuntu.sh
sudo /bin/bash install-ubuntu.sh
For other linux distributions, you may need to modify the installation script to install properly.
The installation script may request administrator privileges.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-macos.sh)"
Or
wget https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-macos.sh
sudo chmod +x install-macos.sh
sudo /bin/bash install-macos.sh
The installation script may request administrator privileges.
Temporarily not supported
First you need to write a legal StaticScript code file as following.
// test.ss
let content: string = "Hello World";
ss_println_string(content);
Then execute the following command from the command line.
staticscript test.ss -o test
./test
Here are some variable declarations.
let flag: boolean = true;
let count: number = 20;
let content: string = "Hello World";
Thanks to the type inference feature of StaticScript, we can write the above variable declaration as follows. They are exactly equivalent.
let flag = true;
let count = 20;
let content = "Hello World";
The compiler of StaticScript cleverly deduced the type of the variable from the initial value.
In addition to using let
to declare variables, you can also use const
to declare constants.
const name = "StaticScript";
const age = 1;
const developing = true;
The difference between let
and const
is that constants declared with const
cannot be modified.
You can use a wealth of operators to perform operations on variables, including arithmetic operations, bitwise operations, logical operations, relational operations, assignments, and string concatenation.
let a = 1;
let b = 2;
// add, subtract, multiply and divide
let sum = a + b;
let diff = a - b;
let product = a * b;
let quotient = a / b;
a = a << 1; // equivalent to `a <<= 1`
b = b >> 1; // equivalent to `b >>= 1`
let year = "2020", month = "08", day = "06";
let birthday = year + "/" + month + "/" + day;
let a = 1;
let b = 100;
if (a < b) {
ss_println_string("b is bigger");
} else {
ss_println_string("b is not bigger");
}
let max = a;
if (a < b) {
max = b;
}
StaticScript supports using while
statement and for
statement to do some repetitive things.
// Calculate the sum of all even numbers between [1, 100]
let sum1 = 0;
let i = 1;
while(i <= 100) {
if (i % 2 == 0) {
sum1 += i;
}
}
// Calculate the sum of all integers between [1, 100]
let sum2 = 0;
for(let i = 1; i <= 100; i++) {
sum2 += i;
}
StaticScript supports defining functions in the top level scope and using function in any scope.
function add(a: number, b: number): number {
return a + b;
}
The above function can omit the return type because StaticScript can deduce the return type through the expression of the return statement.
It is important to note that the parameter types of functions must be explicitly declared.