Core Types
These are the basic data types that you’ll see anywhere that solus runs, there are also usertypes, but those are up to whatever application embeds the VM to provide.
fun
A compiled solus function, represented by either bytecode or a C function pointer for API calls. The function call syntax in solus is very conventional, but the function definition syntax may be a little unique for new users. A function in solus is defined first by its captures [a, b, c], then its arguments (a, b, c), and then the function body as a block. Upvalues are automatically promoted so that their lifetime is at least as long as the function, and do not need to be passed as arguments to reference them.
Example
var x = 4;
var local = [x](a) { # [captures](args)
x += a;
};
var(2);
io.println(x); # 6Note: You may also see captures referred to as “upvalues.” This is the formal name used internally in the VM.
obj
An object type, this functions very similarly to tables in Lua or objects in JavaScript. All objects are references and to make a copy of an object you must construct a new one. Two objects can be joined into a new one by using +, and += will append members or array elements to an object.
Operators
| Operator | Types | Description |
|---|---|---|
. [] | str | Member Access |
+ | obj | Join (new) |
+= | obj | Join (append) |
-= | str | Delete member |
Construction
var local = {
member = 2
other_member = 3, # Optional commas
};Concatenation
var obj = {};
obj += { x = 2 }; # Same obj as beforestr
The string type of solus, this type is very simple to work with and lends itself naturally to programmers’ expectations. It does not require any special functions or operators for concatenation.
Operators
| Operator | Types | Description |
|---|---|---|
+ | str | Concatenation |
Construction
var local = "str";i64
A 64 bit integer, the only integer type supported by solus natively. Although, this may change in the future.
Operators
| Operator | Types | Description |
|---|---|---|
+ | i64 f64 | Add |
- | i64 f64 | Subtract/Negate |
* | i64 f64 | Multiply |
/ | i64 f64 | Divide |
Construction
var local = 1;f64
A 64 bit floating point number, the only floating point type supported by solus natively. Although, this may change in the future.
Operators
| Operator | Types | Description |
|---|---|---|
+ | f64 i64 | Add |
- | f64 i64 | Subtract/Negate |
* | f64 i64 | Multiply |
/ | f64 i64 | Divide |
Construction
var local = 3.14;bool
A value that can only be true (1) or false (0).
Operators
| Operator | Description |
|---|---|
! - | Invert |
Construction
var local = true;
var nvar = !local; # falseerr
A type representing a failure condition, containing a string for the reason. This is for result-like error handling in solus, without the need for protected calls.
Construction
var local = err("Error!");panic
A type that the user cannot handle themselves, a panic is solus’ form of exceptions. Unless caught in a protected call, this will exit the program and show the line where it originated. When caught by catch or attempt, it will be transformed into the err type.
Construction
panic("Critical Failure");