0.0.4 • Published 3 years ago
lightpl v0.0.4
Get started
Install
npm i -g lightpl
To execute:
light <file_name>To translate to js:
light <file_name> -jsHello world
To print "Hello world" in terminal, create new file hello_world.lpl, then print:
print('Hello world')and run(in terminal):
light hello_world.lplLanguage tour
Variables
Variables can be defined with "var" keyword
var variableNameMultiple variables can be defined together, separated by coma
var variable1, variable2, variable3During definition variables can be initialized
var variable = 0Values
Number
Variables can contain number
var variable = 0String
String should be in single quote
var variable = 'Hello world'Bool
Bool is one of two literals
var on = true
var off = falseNull
Null represent nothing
var empty = nullCollections
List
to store similar data you can use lists
var list = [1, 23, 1234]Map
to store data as "key" "value" pares
var legs = [
'dog': 4,
'cat': 4,
'spider': 8
]Control flow statements
If
if statements with optional else statements:
if age < 18 {
print('Access deny')
} else {
print('Hello')
}While
A while loop evaluates the condition before the loop:
while apples > 0 {
print('You have ' + apples + ' apples')
apples = apples - 1
}For
"for" is iteration for collections:
for var item in beg {
print(item)
}Operations
Mathematical
'+', '-', '*', '/'
var ourMoney = myMoney + yourMoneyComparision
'==', '!=', '>=', '<=', '>', '<'
if playerHealth == 0 {
print('You lose')
}Logical
'!', '&&', '||'
if day == 'sunday' || day == 'saturday' {
print('This is weekend')
}Comments
you can comment your code to explain it purpose
// We store time in seconds but show it in minutes
print(time / 60)