thingscript

command module
v0.0.0-...-9edbcb8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

codecov

ThingScript is a script interpreter that implemented in Go with zero dependency. It can be embedded in your Go application as a library, and install as an executable binary.

Hello World

out := import("fmt")
name := "World"
out.println("Hello", name, "?")

Data Types

STRING

Double quoted text in unicode.

var str1 = "hello"
str2 := "world"
str3 := str1 + " "+ str2

BOOLEAN

true and false

var b1 = true
b2 := false
b3 := 10 < 20 // true

INTEGER

64 bit integer number

var i1 = 123
zero := 0

FLOAT

64 bit floating point number

var f1 = 3.14
zero := 0.0

ARRAY

var arr = [ 0, 1, true, "hello world"]

MAP

var tbl = { "key1": 0, "key2": 1, "key3": true, "key4": "hello world"}

Control Flow

IF-ELSE

var n = 10
var m = 20

max := if n > m { n } else { m }

WHILE

var n = 0
var sum = 0
while n < 10 {
    sum += n
    n += 1
}

DO-WHILE

var n = 0
var sum = 0
do {
    sum += n
    n += 1
} while n < 10;

FOREACH

sum := 0
[1,2,3].foreach(func(idx,elm){
    sum += elm
})
// sum = 6
sum := ""
["1","2","3"].foreach(func(idx,elm){
    sum += elm
})
// sum = "123"

Function


func inc(x) {
    x + 1 // 'return' is optional
}

func dec(x) {
    return x - 1
}

eleven := inc(10)
nine := dec(10)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL