Nodix feature a unique script language, allowing easy programing of network message handler, with a synthax close to javascript, and variable convertible to javascript objects.
Script code is oriented around event handler definition to facilitate asynchronous and/or parallel execution.
There can be two types of scripts.
Application script allow to define initial configuration, module dependencies, and event handlers associated to a message list.
Web page script allow to generate dynamic and interactive html5 pages using application modules, allowing embeding of script variable into javascript code and generating javascript based on dynamic data. It supports query string parsing, cookies, html forms and rpc/json.
Declarative statement are executed once when the script is loaded, and correspond to script global variables.
Code statement are used inside of script procedures, event handlers or web pages.
Statements used in page script
The script language allow to declare variable using a variant of json object declaration, as well as messages handler and initilization function.
All variable but function parameters are global to the whole script scope.
let NODE_GFX_OBJECT my_object = ` {"name":"myobject",(NODE_BITCORE_MSG_LIST) "msg_queue" : []} `
let NODE_MODULE_DEF node_adx = ` { "file" : "modz/node_adx.tpo","order":0} `
handler on_msg(node, msg) = ` node_adx.process_msg(node,msg); `
proc init_node = ` sethandler my_object.msg_queue{ "cmd=msg" } = on_msg; `
mem_zone_ref vars={PTR_NULL}, proc={PTR_NULL};
if(ret)ret = load_script("nodix.node", &vars,3);
if(ret)ret = resolve_script_var ( &vars, PTR_NULL, "init_node", NODE_SCRIPT_PROC, &proc);
if(ret)ret = execute_script_proc (&vars, &proc);
if(resolve_script_var(&vars, PTR_NULL, "my_object.msg_queue", NODE_BITCORE_MSG_LIST, &msg_list)) {
if(ret)ret=tree_manager_set_child_value_str(msg,"cmd","msg");
if(ret)ret=tree_manager_node_add_child(&msg_list, msg);
release_zone_ref(&msg_list);
}
if (!ret)log_output("could not emit message \n");
The script language used for webpage is identical to the language used for application, but all function have additional built in parameters to handle the http protocol.
The built in webserver allow automatic execution of function defined in a script with url in for the form
"/script_file.site/page_function/param1/param2"
to execute the procedure page_function defined in the script 'script_file.site' at the root of the webfolder.
let NODE_JSON_ARRAY stylesheets = `["/assets/plugins/bootstrap/css/bootstrap.min.css", "/assets/css/style.css"]`
let NODE_JSON_ARRAY scripts = `["/assets/plugins/jquery/jquery.min.js", "/assets/plugins/bootstrap/js/bootstrap.min.js", "/assets/js/custom.js"]`
let NODE_JSON_ARRAY metas = `[{"viewport" : "width=device-width, initial-scale=1.0"}, {"description" : ""}, {"author" : ""}]`
push scripts,"/assets/js/blocks.js"
html_head "NodiX INDEX PAGE"
html_block "templates/menu.html"
html_block "templates/node.html"
html_scripts
html_var SelfNode;
html_js
site_base_url = '/nodix.site';
api_base_url ='';
lang = 'en';
$('#node_name').html(SelfNode.user_agent);
$('#node_version').html(SelfNode.version);
$('#node_bheight').html(SelfNode.block_height);
get_node_lag(SelfNode)
end_js
html_block "templates/footer.html"
success
push data< handler_data.write_group;
if(payload.block)
push data< payload.block;
success
endif
if(payload.header)
push data< payload.header;
success
endif
error