Version 1.0.1 Stable - A simple, powerful scripting language with Python-like syntax, comprehensive error reporting, and built-in libraries.
✨ Features: Modern error handling • Rich library ecosystem • Multi-language support • IDE integration
LSL (Light Scripting Language) is a lightweight scripting language designed for simplicity and readability. It supports basic data types, control structures, functions, classes/objects, file operations, and useful built-in functions.
Blocks are delimited explicitly with keywords like end (or elif/else for conditionals), so indentation is optional (though recommended for readability).
42, 3.14)"hello" or 'hello' (supports escape sequences like \n, \t)true, falsenull[1, "a", true]{key: "value", age: 30}Variables are created on first assignment (no declaration needed).
x = 10
name = "Alice"
flag = true
data = [1, 2, 3]
config = {host: "localhost", port: 8080}
if x > 0:
print "positive"
elif x < 0:
print "negative"
else:
print "zero"
end
while x < 10:
print x
x = x + 1
end
do:
print x
x = x + 1
end
while x < 10
for i in 1..10:
print i
end
for item in my_list:
print item
end
loop 5:
print "hello"
end
function greet(name):
print "Hello, " + name
return "done"
end
call greet("Bob") # standalone call
result = call greet("Alice") # call for return value
print result
Functions can have parameters and return values (or null if no return).
LSL supports object-oriented programming with classes, methods, and instance variables.
class Person:
function __init__(name, age):
self.name = name
self.age = age
end
function greet():
print "Hi, I'm " + self.name + " and I'm " + self.age + " years old"
end
function have_birthday():
self.age = self.age + 1
print "Happy birthday! Now I'm " + self.age
end
end
# Create instances
p1 = new Person("Alice", 30)
p2 = new Person("Bob", 25)
# Call methods
p1.greet() # Hi, I'm Alice and I'm 30 years old
p2.greet() # Hi, I'm Bob and I'm 25 years old
# Access properties directly
print p1.name # Alice
print p2.age # 25
# Modify properties
p1.have_birthday() # Happy birthday! Now I'm 31
print p1.age # 31
class Calculator:
function __init__():
self.result = 0
end
function add(x):
self.result = self.result + x
return self.result
end
function multiply(x):
self.result = self.result * x
return self.result
end
function reset():
self.result = 0
end
end
calc = new Calculator()
print calc.add(5) # 5
print calc.add(3) # 8
print calc.multiply(2) # 16
calc.reset()
print calc.result # 0
__init__ method is called when creating instances with newself.variable_name to store object stateselfobject.method(args) syntaxobject.property to read/write instance variables💡 Important: Method calls can be used directly as expressions without 'call' keyword. Use object.method(args) for method calls. Use call function_name(args) for function calls.
| Function | Description | Example |
|---|---|---|
print expr | Outputs value | print "hello" |
input "prompt" | Read user input with prompt | name = input "Enter name: " |
len(obj) | Length of string/list/dict | len("abc") |
substring(str, start, len) | Substring | substring("hello", 1, 3) |
replace(str, old, new) | Replace all occurrences | replace("aabb", "a", "c") |
trim(str) | Remove leading/trailing whitespace | trim(" hi ") |
split(str, sep) | Split string | split("a,b,c", ",") |
readfile "path" | Read entire file as string | content = readfile "data.txt" |
writefile "path", data | Write data to file | writefile "out.txt", "hello" |
appendfile "path", data | Append to file | appendfile "log.txt", "event" |
createdir "path" | Create directory | createdir "newfolder" |
listdir "path" | Returns list of entries | files = listdir "." |
deletedir "path" | Delete directory | deletedir "temp" |
exists path | File/directory exists? | if exists "file.txt": ... |
# Interactive input
name = input "What's your name? "
age = input "How old are you? "
print "Hello, " + name + "!"
print "You are " + age + " years old."
# Simple calculator
print "Simple Calculator"
num1 = input "Enter first number: "
num2 = input "Enter second number: "
result = num(num1) + num(num2)
print "Result: " + result
use "mymodule.lsl" as my
result = my.my_function(42)
Loads another LSL file and makes its functions available under the given prefix.
LSL includes built-in libraries that extend functionality with additional functions. Use them with the use command.
Load with: use math
| Function | Description | Example |
|---|---|---|
sin(x) | Sine (degrees) | sin(90) |
cos(x) | Cosine (degrees) | cos(0) |
tan(x) | Tangent (degrees) | tan(45) |
sqrt(x) | Square root | sqrt(16) |
pow(x, y) | Power function | pow(2, 3) |
log(x) | Natural logarithm | log(10) |
exp(x) | Exponential function | exp(1) |
factorial(x) | Factorial | factorial(5) |
use math
print sin(90) # 1
print sqrt(25) # 5
print pow(2, 4) # 16
print factorial(6) # 720
Load with: use string
| Function | Description | Example |
|---|---|---|
contains(text, substr) | Check if text contains substring | contains("hello", "ell") |
startswith(text, prefix) | Check if text starts with prefix | startswith("hello", "he") |
endswith(text, suffix) | Check if text ends with suffix | endswith("hello", "lo") |
to_upper(text) | Convert to uppercase | to_upper("hello") |
to_lower(text) | Convert to lowercase | to_lower("HELLO") |
use string
print contains("hello world", "world") # true
print startswith("hello", "he") # true
print endswith("hello", "lo") # true
print to_upper("hello world") # HELLO WORLD
Load with: use list
Advanced list manipulation functions (coming soon).
Load with: use advanced
Advanced programming functions like map, filter, reduce (coming soon).
LSL provides comprehensive error reporting with precise line numbers and detailed error messages.
# Syntax Error examples
print "unclosed string # [Syntax Error at line 1: Unclosed string literal]
unknown_command # [Syntax Error at line 2: Unknown command: unknown_command]
bad_function() # [Syntax Error at line 3: Function calls must use 'call' keyword]
# Runtime Error examples
use math
print sqrt(-1) # [Runtime Error at line 6: sqrt() expects a non-negative number]
💡 Pro Tip: All errors include line numbers for quick debugging. The IDE highlights error lines automatically.
function factorial(n):
if n <= 1:
return 1
else:
return n * call factorial(n - 1) # recursive call
end
end
result = call factorial(6) # call for return value
print "Factorial of 6 is: " + result
use math
# Number guessing game
secret = call num(call sqrt(random() * 100)) # Random number 1-10
attempts = 0
max_attempts = 5
print "I'm thinking of a number between 1 and 10!"
print "You have " + max_attempts + " attempts."
while attempts < max_attempts:
guess = input "Enter your guess: "
guess_num = call num(guess)
attempts = attempts + 1
if guess_num == secret:
print "🎉 Congratulations! You got it in " + attempts + " attempts!"
break
elif guess_num < secret:
print "Too low! Try again."
else:
print "Too high! Try again."
end
if attempts == max_attempts:
print "Game over! The number was " + secret
end
end
class TodoManager:
function __init__():
self.todos = []
end
function add(task):
self.todos = self.todos + [task]
print "Added: " + task
end
function list():
if len(self.todos) == 0:
print "No tasks yet!"
else:
print "Your tasks:"
for i in 1..len(self.todos):
print i + ". " + self.todos[i-1]
end
end
end
function remove(index):
if index > 0 and index <= len(self.todos):
removed = self.todos[index-1]
# Remove item by creating new list without it
new_todos = []
for i in 1..len(self.todos):
if i != index:
new_todos = new_todos + [self.todos[i-1]]
end
end
self.todos = new_todos
print "Removed: " + removed
else:
print "Invalid task number!"
end
end
end
# Usage
todo = new TodoManager()
todo.add("Learn LSL programming")
todo.add("Build a project")
todo.list()
todo.remove(1)
todo.list()
class FileProcessor:
function __init__(filename):
self.filename = filename
self.content = ""
end
function read():
if exists self.filename:
self.content = readfile self.filename
print "Read " + len(self.content) + " characters from " + self.filename
return true
else:
print "File not found: " + self.filename
return false
end
end
function count_words():
words = call split(self.content, " ")
return len(words)
end
function count_lines():
lines = call split(self.content, "\n")
return len(lines)
end
function word_frequency():
words = call split(self.content, " ")
freq = {}
for word in words:
word = call to_lower(call trim(word))
if word != "":
if freq[word]:
freq[word] = freq[word] + 1
else:
freq[word] = 1
end
end
end
return freq
end
end
# Usage
processor = new FileProcessor("sample.txt")
if processor.read():
print "Words: " + processor.count_words()
print "Lines: " + processor.count_lines()
freq = processor.word_frequency()
print "Unique words: " + len(freq)
end
This guide covers the current AST-based implementation. The language is still evolving.