-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04-addIntrinsic.html
More file actions
30 lines (30 loc) · 818 Bytes
/
Copy path04-addIntrinsic.html
File metadata and controls
30 lines (30 loc) · 818 Bytes
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
<!DOCTYPE html>
<html>
<link rel="shortcut icon" href="#">
<head>
<meta charset="UTF-8">
<title>MiniScript.TS - Adding intrinsics</title>
<script type="text/javascript" src="../../dist/miniscript-ts.js"></script>
</head>
<body>
<div>
This example shows how to add an intrinsic function.
</div>
<div>
Open the developer console to see results!
</div>
<script type="text/javascript">
const interp = new MiniScriptTs.Interpreter();
// Use a MiniScript function signature. Default values are supported.
// Then provide a JavaScript anonymous function.
interp.addIntrinsic("mySum(a=0,b=0)", (a, b) => {
return a + b;
});
// Let's call the intrinsic
let code = `
print mySum(8,4)
print mySum(2)`;
interp.runSrcCode(code);
</script>
</body>
</html>