starlight-cli
v1.1.21
Published
Starlight Programming Language CLI
Downloads
414
Maintainers
Readme
Starlight Language Guide
Welcome to Starlight Language, a simple and expressive server-side scripting programming language designed for clarity and flexibility.
This guide introduces the core concepts and syntax to help you start writing programs quickly.
1. Hello World
sldeploy "Hello, world!"2. Variables
Variables are declared using the define keyword.
define name = "Alice"
define age = 20Supported Value Types
| Type | Example |
| ------- | -------------------- |
| Number | 10, 3.14 |
| String | "hello" |
| Boolean | true, false |
| Array | [1, 2, 3] |
| Object | { "a": 1, "b": 2 } |
| Null | null |
3. Output
Use sldeploy to print values:
sldeploy name
sldeploy age4. Input
Use ask to read user input:
define name = ask("Enter your name:")
sldeploy "Hello " + name5. Operators
Arithmetic Operators
| Operator | Description |
| -------- | -------------- |
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
Example:
define result = 10 + 5 * 2Comparison Operators
| Operator | Description |
| -------- | --------------------- |
| == | Equal |
| != | Not equal |
| < | Less than |
| <= | Less than or equal |
| > | Greater than |
| >= | Greater than or equal |
Logical Operators
| Operator | Description |
| -------- | --------------- |
| AND | Logical AND |
| OR | Logical OR |
| ?? | Null coalescing |
Example:
define x = null ?? 106. Conditional Statements
if (age > 18) {
sldeploy "Adult"
} else {
sldeploy "Minor"
}7. Loops
While Loop
define i = 0
while (i < 5) {
sldeploy i
i = i + 1
}For Loop
for (define i = 0; i < 5; i = i + 1) {
sldeploy i
}For-In Loop
define arr = [10, 20, 30]
for x in arr {
sldeploy x
}8. Functions
Function Declaration
func add(a, b) {
return a + b
}Function Usage
define result = add(2, 3)
sldeploy resultArrow Functions
define add = (a, b) => a + b9. Arrays
define arr = [1, 2, 3]
sldeploy arr[0]Common Array Operations
| Function | Description |
| -------- | ------------------- |
| push | Add element |
| pop | Remove last element |
push(arr, 4)
pop(arr)10. Objects
define user = {
"name": "Alice",
"age": 20
}
sldeploy user.name11. Slicing
define arr = [1, 2, 3, 4, 5]
sldeploy arr[1:4]
sldeploy arr[0:5:2]Slice Syntax
| Format | Description |
| ------------------ | ------------------ |
| [start:end] | Basic slicing |
| [start:end:step] | Step-based slicing |
12. Error Handling
do {
define x = y
} track {
sldeploy "Error occurred"
}13. Imports
import math from "math"Supported Imports
| Type | Description |
| --------------- | --------------------- |
| .sl files | Local modules |
| Node.js modules | External dependencies |
14. Built-in Functions
Examples:
len([1,2,3])
upper("hello")
random(1, 10)Categories
| Category | Examples |
| -------- | ---------------- |
| String | upper, lower |
| Array | push, pop |
| Math | random |
| Utility | len |
15. Asynchronous Code
define data = await get("https://api.example.com")
sldeploy data16. Object Construction
func Person(name) {
this.name = name
}
define p = new Person("Alice")
sldeploy p.name17. Comments
# This is a comment18. Language Notes
| Behavior | Description |
| ---------------- | --------------------------------- |
| Undefined values | Treated as null |
| Function return | Defaults to null if unspecified |
| Data structures | Dynamic (arrays and objects) |
| Error reporting | Includes line and column details |
19. Next Steps
- Explore built-in functions
- Write small programs
- Review full syntax reference
- Experiment with custom scripts
Keywords
starlight language, scripting language, programming language tutorial, interpreter language, CLI scripting, custom language design
