-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
43 lines (43 loc) · 1.49 KB
/
main.js
File metadata and controls
43 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* eval ruby script and return integer value
* Arguments are accessible as $arg1, $arg2, $arg3 in Ruby code.
* @param {string} text ruby code.
* @param {...(string|number|Array<Array<string|number>>)} args arguments accessible as $arg1, $arg2, $arg3 (up to 3 arguments).
* @return The result of the Ruby script (type inferred from JSON).
* @customfunction
*/
function EVAL_RUBY_SCRIPT(text) {
var args = Array.prototype.slice.call(arguments, 1);
var result;
if (args.length === 0) {
result = Module.ccall(
'eval_ruby_script_returning_json',
'string',
['string'],
[text]
);
} else if (args.length === 1) {
result = Module.ccall(
'eval_ruby_script_returning_json1',
'string',
['string', 'string'],
[text, JSON.stringify(args[0])]
);
} else if (args.length === 2) {
result = Module.ccall(
'eval_ruby_script_returning_json2',
'string',
['string', 'string', 'string'],
[text, JSON.stringify(args[0]), JSON.stringify(args[1])]
);
} else {
// 3 or more arguments - use json3 (max 3 args supported)
result = Module.ccall(
'eval_ruby_script_returning_json3',
'string',
['string', 'string', 'string', 'string'],
[text, JSON.stringify(args[0]), JSON.stringify(args[1]), JSON.stringify(args[2])]
);
}
return JSON.parse(result);
}