Globals
parseData(json) - JSON parser. Evaluates input literal and returns its value. Input must contain valid data literal expression otherwise parsing exception will be thrown.
rand(maxNumber) - Returns a random number limited from 0 to mxNumber-1.
symbol(text) - Returns symbol of the string.
gc() - Runs garbage collector.
membersOf(obj) - Returns map (simple object) that has the same set of properties as the obj. Main purpose of membersOf is to be used like enumerations to scan properties of entities that have different semantic of enumeration than instances of Object.
Example:
function foo()
{
}
foo.bar = 1; // adding property 'bar' to the
// foo function (that is an object too)
for (var (k,v) in membersOf(foo))
console << k << "=" << v << "\n";
crackUrl(url) - Parses the url string. Returns an object with individual fields. See the following example:
crackUrl("http://public::8443/svn").show();
displays
Class Object: [object Class]
Properties:
params: ""
dir: ""
ext: ""
port: 8443
name_ext: "/svn"
protocol: "http"
name: "/svn"
hostname: "mothiva.com"
anchor: ""
username: "public"
password: "mothiva.com:8443"
toInteger(obj) - Converts given object to an integer value. If there is no conversion possible this function returns undefined.
console << toInteger(10) << "\n";
// displays 10 console << toInteger(true) << "\n";
// displays 1 console << toInteger(false) << "\n";
// displays 0 console << toInteger("12345") << "\n";
// displays 12345 console << toInteger("x12345") << "\n";
// displays undefined console << toInteger(null) << "\n";
// displays 0 console << toInteger(undefined) << "\n";
// displays 0 console << toInteger({x: 10, y: 10}) << "\n";
// displays undefined
toFloat(obj) - Converts given object to a float value. If there is no conversion possible this function returns undefined.
hash(obj) - Returns hash value of its argument.
store(path|stream, obj) and fetch(path|stream)
Store - stores the value into file or stream in binary form. Returns true if data was stored successfully.
Fetch - restores value previously written into the file or stream by function store. Returns value or null if operation failed.
See example:
// display true, if object was stored in binary.dat
console << store("app://binary.dat", {x: 10, y: 20}) << "\n" // load object form binary form
var obj = fetch("app://binary.dat");
if (obj == null)
throw "Cannot load object"; // displays x=10, y=20
console << "x=" << obj.x << ", y=" << obj.y << "\n";
Console and debug functions
Standard console stream represents global variable console. Console is a panel on the bottom-left in IDE, with name console. All messages during emulator run via IDE are transferred to this panel.
console << "Some text\n";
Moscrif supports following commands for further debugging.
- debug namespace
- debug stacktrace
- assert
debug namespace displays current content of all namespaces in running application.
debug stacktrace displays current call stack in console. All called functions are displayed in order of call.
assert is a statement that allows to test your assumptions in your code. Assertion statement starts from keyword “assert” followed by expression to test and optional additional expression to show in console output:
assert [ : ] ;
Examples:
var i = 10;
assert i < 5;
// Error: Assertion failed on "i < 5":String
or
var i = 10;
assert i < 5 : "Less than 5 required!";
// Error: Assertion failed on "i < 5 ":String when "Less than 5 required!":String