mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
957 B
36 lines
957 B
/*
|
|
* Example adapted from http://wiki.commonjs.org/wiki/Modules/1.1.1
|
|
*/
|
|
|
|
/*===
|
|
Duktape.modSearch program
|
|
Duktape.modSearch increment
|
|
Duktape.modSearch math
|
|
2
|
|
===*/
|
|
|
|
Duktape.modSearch = function (id) {
|
|
print('Duktape.modSearch', id);
|
|
return {
|
|
math: 'exports.add = function() {\n' +
|
|
' var sum = 0, i = 0, args = arguments, l = args.length;\n' +
|
|
' while (i < l) {\n' +
|
|
' sum += args[i++];\n' +
|
|
' }\n' +
|
|
' return sum;\n' +
|
|
'};\n',
|
|
increment: 'var add = require(\'math\').add;\n' +
|
|
'exports.increment = function(val) {\n' +
|
|
' return add(val, 1);\n' +
|
|
'};\n',
|
|
program: 'var inc = require(\'increment\').increment;\n' +
|
|
'var a = 1;\n' +
|
|
'print(inc(a));\n'
|
|
}[id];
|
|
};
|
|
|
|
try {
|
|
require('program');
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|