File: prism-chaiscript.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (56 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
<h2>Full example</h2>
<pre><code>// http://chaiscript.com/examples.html#ChaiScript_Language_Examples
// Source: https://gist.github.com/lefticus/cf058f2927fef68d58e0#file-chaiscript_overview-chai

// ChaiScript supports the normal kind of control blocks you've come to expect from
// C++ and JavaScript


if (5 > 2) {
  print("Yup, 5 > 2");
} else if (2 > 5) {
  // never gonna happen
} else {
  // really not going to happen
}

var x = true;

while (x)
{
  print("x was true")
  x = false;
}

for (var i = 1; i &lt; 10; ++i)
{
  print(i); // prints 1 through 9
}


// function definition

def myFunc(x) {
  print(x);
}

// function definition with function guards
def myFunc(x) : x > 2 && x &lt; 5 {
  print(to_string(x) + " is between 2 and 5")
}

def myFunc(x) : x >= 5 {
  print(t_string(x) + " is greater than or equal to 5")
}

myFunc(3)

// ChaiScript also supports in string evaluation, which C++ does not

print("${3 + 5} is 8");

// And dynamic code evaluation

var value = eval("4 + 2 + 12");

// value is equal to 18</code></pre>