System Functions

From Onix OS Wiki
Jump to: navigation, search

itostr

Convert integer to string. But strings and integers not connect with plus iteration (Ex: “Hello”+0 => impossible need to convert 0 or “Hello” to string or integer in IRL [In real life]).

Example

def i = 0;
0
def str = itostr(i)
# => "0"

len

Gives something to length. Sometimes usefull for length calculation. Easy to use.

Example

def arr = [1,2,3,4,5]
def lenArr = len(arr)
# => 5

first

All objects gives first item. That's all.

Example

def hsh = {"x":10, "y":20, "z":30}
def fhsh = first(hsh)
{"x":10}
def arr = [1,2,3,4,5]
def farr = first(arr)
# => 1

last

All objects gives last item. That's all.

Example

def hsh = {"x":10, "y":20, "z":30}
def fhsh = last(hsh)
{"z":30}
def arr = [1,2,3,4,5]
def farr = last(arr)
# => 5

rest

Extract first element from arrays;

def arr = [1,2,3,4,5]
len(arr)
# => 5
rest(arr)
len(arr)
# => 4
arr
# => [2,3,4,5]


push

Add element to arrays;

def arr = [1,2,3,4,5]
push(arr, 6)
[1,2,3,4,5,6]

println

Print every type convert string and show one line;

def hello = "Hello";
println(hello)
# => "Hello\n"

show

Print every type convert string and show directly;

def hello = "Hello";
show(hello)
# => "Hello"

colorize

This is colorize function colorize some object and show directly. Run only ASCII consoles. You need to enabled colors.

colorize(colorstring, string, background:true|false)

Color List

red
blue
green
yellow
grey
black
bold
magenta
white

http

Runs http server with string or rendered objects.

http(routepath, port, string object);

https

Runs http server with string or rendered objects.

http(route path, port, string object, crt key, server key);

file

Opens some file gives content directly.

def definition = file(file name)

Example

def hellofile = file("hello.txt")
# => "This is test file content for example"

atostr

Gives some arrays from some key with string object.

Example

def arr = [1,2,3,4,5]
atostr(arr, 0)
# => "1"

router

Router definition function. Simple create router use for web servers or micro servers.

router(port, hash definition);

Example

def config = {
  "/": {
    "type": "GET",
    "response": "Hello!",
  },
};
router("8080", config)

Defined new route with this example;

GET http://0.0.0.0:8080/
"Hello!"

createdb

Creates new database with inline named folder.

createdb(dbname)

Created new key based database in current folder.

insertdb

Insert database something.

insertdb(dbname, key, value)

getdb

Get database with some key.

getdb(dbname, key)

deletedb

Delete database with some key.

deletedb(dbname, key)

searchdb

Directly search all database with get all objects.

searchdb(dbname, some string)

getval

Get some value converts to string. After automaticaly show or define value.

Example

def x = 12;
getval(x)
# => "12"

jsonp

Automaticaly parse json string and return hash object.

Example

def js = "{val1:1,val2:2}"
jsonp(js)
# => {"val1":1, "val2":2}

xmlp

Convert all xml string to hash or array object

Example

def xmlo = "<arr><type1>1<type1><type2>2<type2><type3>2<type3></arr>"
xmlp(xmlo)
# => {"arr":{"type1":1,"type2":2,"type3":3}}

wdir

Return current working directory.

wdir()
# => "/home/oytun/olang/"

chdir

Change directory and return changed directory.

chdir("/home/oytun/olang/")
"/home/oytun/olang/"

renderf

File render function. Some objects to render some file and gives string.

Example

file.txt:

{{.output}}

script:

renderf("file.txt", {"output": "O Language Render Example"})

result:

Olang Render Example

sysenv

Shows system environment tables or set some environment variable

sysenv(some system environment string, ...some system environment string)

Example

sysenv("PATH")
# => /usr/local/bin:/bin:/usr/bin


proc_kill

Kill some proccess with system pid

proc_kill(pid integer only)

Example

proc_kill(330)
# => ...killed 330 pid application or service

proc_exec

Execute some system command in background and return Process object.

proc_exec(command strings...)

Example

proc_exec("ls -al")
# => Files....

proc_out

Executed process show or define output

proc example "ls" "/home/olang" ["-lha"]
proc_out(example)
# => .....files


proc_pid

Executed process pid return

proc example "ls" "/home/olang" ["-lha"]
proc_pid(example)
# => 12345 (proc pid)

inspect

This is debugging function for variables.

inspect(...objects)

Example

def x = 1;
inspect(x)
# => 1


regexp_check

Check regexp and string return bool object result.

def rex = "[A-Z][a-z]"
def matched = regexp_check(rex, "Hello!")
# => true


regexp_find

Find all regexp results and return array object.

def rex = "el"
def matched = regexp_find(rex, "Hello!")
# => ["el"]

dial_service

Create dial messaging service from socket. All requests and response need to hash iteration.

sock socket "tcp4" "9050" "0.0.0.0";
def messages = {"ping": "pong"}
dial_service(socket, messages);

Created dial service.

dial_send

Send messages to dial_service

sock socket "tcp4" "9050" "0.0.0.0"
dial_send(socket, "ping")
Returns “pong” called from dial_service.

quit

Quit from olang

quit()