< Back

Editor API

Built-in functions

reqire(library)

var foolib = require("foo-lib");

exports

examples

/* CatzLib.js */
var log = require('logger');

exports.greet = fucntion(what) {    
    log.info("Meow " + what);
}

/* Sctript.js */

var cat = require("CatzLib");

cat.greet("John");  // Will output "Meow John"

Helper libraries

logger

The logger functions allow you to log information in the logger window, there are three functions witch accept one argument - a string to be logged on the window. You can also pass an object which will be converted to a string.

logger.dir(object, options)

logger.info(message)

logger.error(message)

logger.warn(message)

var log = require('logger'),

log.info("Hello World");
log.info({"hello":"word"});

documents

The documents functions allow you to manipulate file contests. The files should be opened in the editor.

documents.list()

documents.get_data(docname)

documents.set_data(docname, data)

var docs = require('documents');

/* Get the names of all the opened files */
var docNames = docs.list();

/* Get the data from great-file.txt (it should be opened in the editor) */
var greatData = docs.get_data("great-file.txt")              

/* Append the data to great-file.txt (it should be opened in the editor) */
docs.set_data("great-file.txt", greatData + " End Of Great File")

Underscore.js

For complex javascript operations a helper library could be included - underscore.js

var _ = require('_');
var obj = { 
    dogs : "bark"
}

_.extend(obj, {
    hello : "word",
    cats  : "jump"
});

// obj is now { dogs : "bark", cats : "jump", hello : "word" }

Server interaction libraries

The api library allows you to send and recive data from and to the server. You can require the api library in the following way:

var api = require('api');

api.mem.write(0x11, [2,3,4,5,56]);

api.mem

The api.mem set of functions allows you to interact with the memory of the microprocessor.

api.mem.read(address, callback)

api.mem.write(address, data, callback)

examples

var SOME_ADDR = 0x4356;
var data = [0x1, 0x2, 0x3, 0x4, 0x5];

var api = require('api');
var log = require('logger');

api.mem.write(SOME_ADDR, mem_data);
data = api.mem.read(SOME_ADDR+2, 2);

log.info("mem.read result = " +    log.dir(data)); // Should output "mem.read result = [0x3, 0x4]"

api.reg

The api.reg set of functions allows you to interact with the registers of the microprocessor.

api.reg.read(register, callback)

api.reg.write(register, data, callback)

api.poll(register, mask, value, ntimes)

api.wait(address, mask, value, callback, delay, ntimes)

examples

var SOME_REG = 12;
var data = 5;

var api = require('api');
var log = require('logger');

api.reg.write(SOME_REG, data);
data = api.reg.read(SOME_REG);

log.info("reg.read result = " +    data); // Should output "mem.read result = 5"