Melang

Logo

A script language of preemptive scheduling coroutine in single thread

View the Project on GitHub Water-Melon/Melang

System

mln_size

Get array length.

@mln_size(&array);

Input:

Return value:

Example:

@mln_print(@mln_size([1, 2, 3]));

Output:

3
mln_isInt

Find whether the type of a variable is integer.

@mln_isInt(var);

Input:

Return value:

Example:

@mln_print(@mln_isInt(1));
@mln_print(@mln_isInt('1'));

Output:

true
false
mln_isReal

Find whether the type of a variable is real.

@mln_isReal(var); 

Input:

Return value:

Example:

@mln_print(@mln_isReal(1));
@mln_print(@mln_isReal(1.0));

Output:

false
true
mln_isStr

Find whether the type of a variable is string.

@mln_isStr(var); 

Input:

Return value:

Example:

@mln_print(@mln_isStr('123'));

Output:

true
mln_isNil

Find whether the type of a variable is nil.

@mln_isNil(var);

Input:

Return value:

Example:

@mln_print(@mln_isNil(0));
@mln_print(@mln_isNil(nil));

Output:

false
true
mln_isBool

Find whether the type of a variable is bool.

@mln_isBool(var);

Input:

Return value:

Example:

@mln_print(@mln_isBool(0));
@mln_print(@mln_isBool(false));

Output:

false
true
mln_isObj

Find whether the type of a variable is object.

@mln_isObj(var);

Input:

Return value:

Example:

set {}
o = $set;
@mln_print(@mln_isObj(o));

Output:

true
mln_isFunc

Find whether the type of a variable is function.

@mln_isFunc(var); 

Input:

Return value:

Example:

@foo() {}
@mln_print(@mln_isFunc(foo));

Output:

true
mln_isArray

Find whether the type of a variable is array.

@mln_isArray(var);

Input:

Return value:

Example:

@mln_print(@mln_isArray([1, 2]));
@mln_print(@mln_isArray(['key1': 1, 'key2':2]));

Output:

true
true
mln_int

Get int value of a variable.

@mln_int(var);

Input:

Return value:

Example:

@mln_print(@mln_int(1.2));
@mln_print(@mln_int('1'));

Output:

1
1
mln_bool

Get bool value of a variable.

@mln_bool(var);

Input:

Return value:

Example:

@mln_print(@mln_bool(1.2));
@mln_print(@mln_bool(0));
@mln_print(@mln_bool(nil));
@mln_print(@mln_bool([]));
@mln_print(@mln_bool(''));

Output:

true
false
false
false
false
mln_real

Get real value of a variable.

@mln_real(var);

Input:

Return value:

Example:

@mln_print(@mln_real(1));
@mln_print(@mln_real('1.2'));

Output:

1.000000
1.200000
mln_str

Get string value of a variable.

@mln_str(var);

Input:

Return value:

Example:

@mln_dump(@mln_str(1));
@mln_dump(@mln_str(1.2));

Output:

  var <Var>    Refer  Alias name: var  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
    <STRING> '1'
  var <Var>    Refer  Alias name: var  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
    <STRING> '1.200000'
mln_obj

Get object value of a variable.

@mln_obj(var);

Input:

Return value:

Example:

@mln_dump(@mln_obj([1, 2]));
@mln_dump(@mln_obj(['name': 'Tom', 'age': 18]));

Output:

  var <Var>    Refer  Alias name: var  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
    <OBJECT> In Set '<anonymous>'  setRef: <unknown> objRef: 2
  var <Var>    Refer  Alias name: var  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
    <OBJECT> In Set '<anonymous>'  setRef: <unknown> objRef: 2
      Normal  Alias name: name  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
      <STRING> 'Tom'
      Normal  Alias name: age  valueRef: 1, udata <0x0>, func <0x0>, notModify: false
      <INT> 18

As we can see in output, common array will not generate any properties in object.

mln_array

Get array value of a variable.

@mln_array(var);

Input:

Return value:

Example:

Human {
  name;
  age;
}
o = $Human;
o.name = 'Tom';
o.age = 18;
arr = @mln_array(o);
@mln_print(arr);
@mln_print(arr['name']);

Output:

[Tom, 18, ]
Tom
mln_keys

Return all the keys or a subset of the keys of an array.

@mln_keys(&array);

Input:

Return value:

Example:

a = ['name': 'Tom', 'age': 18];
@mln_print(@mln_keys(a));

Output:

[name, age, ]
mln_merge

Merge two arrays

@mln_merge(array1, array2);

Input:

Return value:

Example:

a = ['name': 'Tom', 'age': 18];
b = ['name': 'Sam', 'age': 19];
c = [1, 2, 3];
d = [2, 3, 4];
@mln_print(@mln_merge(a, b));
@mln_print(@mln_merge(c, d));
ret = @mln_merge(b, c);
@mln_print(ret);
@mln_print(ret['name']);

Output:

[Sam, 19, ]
[1, 2, 3, 2, 3, 4, ]
[Sam, 19, 1, 2, 3, ]
Sam
mln_has

Checks if a key or property exists in an array or object.

@mln_has(owner, thing);

Input:

Return value:

Example:

a = ['name': 'Tom', 'age': 18];
@mln_print(@mln_has(a, 'name'));

Output:

true
mln_type

Get the type of input argument.

@mln_type(var);

Input:

Return value:

Example:

a = ['name': 'Tom', 'age': 18];
SetA {}
@foo () {}

@mln_print(@mln_type(1));
@mln_print(@mln_type(1.2));
@mln_print(@mln_type('abc'));
@mln_print(@mln_type([1, 2]));
@mln_print(@mln_type($SetA));
@mln_print(@mln_type(foo));
@mln_print(@mln_type(@mln_obj(a)));

Output:

int
real
string
array
SetA
function
object
mln_getProperty

Get property value from an object.

@mln_getProperty(&obj, prop);

Input:

Return value:

Example:

Human {
  name;
}
o = $Human;
o.name = 'Tom';
@mln_print(@mln_getProperty(o, 'name'));

Output:

Tom
mln_setProperty

Set a property with its value in an object.

@mln_setProperty(&obj, prop, &val);

Input:

Return value:

Example:

Human {
  name;
}
o = $Human;
o.name = 'Tom';
@mln_print(@mln_setProperty(o, 'age', 18));
@mln_print(@mln_getProperty(o, 'age'));

Output:

18
18
mln_eval

Create a new coroutine and execute.

@mln_eval(val, data, in_string);

Input:

Return value:

Example: visit Coroutine Section.

mln_mkdir

Create a directory.

@mln_mkdir(path, mode);

Input:

Return value:

Example:

@mln_mkdir('/tmp/aaa');
$ ls -d /tmp/aaa

Output:

/tmp/aaa
mln_remove

Remove directory from file system.

@mln_remove(path);

Input:

Return value:

Example:

@mln_print(@mln_remove('/tmp/aaa'));

Output:

true
mln_exist

Check if the file or directory exists.

@mln_exist(path);

Input:

Return value:

Example:

@mln_print(@mln_exist('/tmp'));

Output:

true