forked from runtimejs/runtime
-
Notifications
You must be signed in to change notification settings - Fork 11
Simple application
ndr-power edited this page Jan 8, 2018
·
3 revisions
Сейчас мы рассмотрим пример простого приложения для JsOS (appman)
Hello world приложение представляет из себя файл index.js в папке helloworld. Вот его содержимое:
// Example application for JsOS 'use strict'; function main(cmd, args, api, res) { const io = api.stdio; // Короткое имя io.setColor('green'); // Устанавливаем зеленый цвет текста io.writeLine('Hello World!!!'); // Выводим на экран текст: Hello World!!! io.writeLine(`Command: ${cmd}; Args: ${args}`); // Command: helloworld; Args: return res(0); // Завершаем программу (0 - всё нормально, 1 - ошибка) } exports.call = main; exports.commands = ['helloworld'];
appman использует параметр commands для регистрации команд запуска (В данном случае, для запуска нужно ввести: start helloworld)
appman при запуске приложения вызывает метод call с такими аргументами:
- cmd {string} - Команда (полезно, если вы указали в exports.commands несколько команд)
- args {string} - Аргументы (текст после команды)
- api {object} - API приложения
- res {function} - Callback для завершения программы
Hello world application is index.js file in helloworld dir. Its contents:
// Example application for JsOS 'use strict'; function main(cmd, args, api, res) { const io = api.stdio; // short name io.setColor('green'); // set font color to green io.writeLine('Hello World!!!'); // display "Hello World!!!" on the screen io.writeLine(`Command: ${cmd}; Args: ${args}`); // Command: helloworld; Args: return res(0); // Finish execution (0 - OK, 1 - ERR) } exports.call = main; exports.commands = ['helloworld'];
appman uses commands parameter to register execution commands (i.e. you should type following command to run the program : start helloworld)
appman calls call method on execution with theese aruments:
- cmd {string} - Command (useful if you defined more than one command in exports.commands )
- args {string} - Arguments (text after the command)
- api {object} - App API
- res {function} - Callback for program to stop