~ubuntu-branches/ubuntu/vivid/emscripten/vivid-proposed

« back to all changes in this revision

Viewing changes to demos/cubescript.html

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<html>
2
 
<head>
3
 
  <title>
4
 
    Emscripten: CubeScript
5
 
  </title>
6
 
  <script src="cubescript.js"></script>
7
 
  <script>
8
 
    // print function which the cubescript engine will call
9
 
    function print(text) {
10
 
      document.getElementById('output').innerHTML += text + '<br>';
11
 
      printed = true;
12
 
    }
13
 
 
14
 
    function execute(text) {
15
 
      printed = false;
16
 
      executeCS(text);
17
 
      if (!printed) {
18
 
        print('<small><i>(no output)</i></small>');
19
 
      }
20
 
    }
21
 
  </script>
22
 
</head>
23
 
<body onload="document.getElementById('the_input').focus()">
24
 
  <p>
25
 
    This is an <a href="http://emscripten.org">Emscriptened</a> <a href="http://sauerbraten.org/docs/config.html#cubescript">CubeScript</a> engine.
26
 
    The CubeScript engine from <a href="http://sauerbraten.org">Sauerbraten</a>, which is about 2,500 lines of C++, was compiled by
27
 
    <a href="http://llvm.org/cmds/llvmgcc.html">llvm-gcc</a> into <a href="http://llvm.org/">LLVM</a> bitcode,
28
 
    which was translated by Emscripten into JavaScript, which
29
 
    you can run in your browser here. In other words, it's a script engine (for one language, and written in C++) running in another script engine
30
 
    (the JavaScript engine in your browser, which is incidentally also written in C++, most likely).
31
 
  </p>
32
 
  </p>
33
 
    Why? <i>[insert Internet meme joke here]</i> Seriously, though, this is a test of the capabilities of
34
 
    <a href="http://emscripten.org">Emscripten</a>, since the CubeScript engine uses fairly complicated C++ (even stuff like
35
 
    manually copying vtable pointers), and since compiling an actual, complete script engine seems like a useful milestone.
36
 
    Also, it's a potential first step
37
 
    towards bringing <a href="http://www.syntensity.com">Syntensity</a> (which is based on Sauerbraten) to the web.
38
 
  </p>
39
 
  <hr>
40
 
  <p>
41
 
    <b>Instructions</b>: For example, try entering the following commands in the input field below:
42
 
    <ul>
43
 
      <li><div style="font-family: Courier New,Courier,monospace;">echo Hello world</div></li>
44
 
      <li><div style="font-family: Courier New,Courier,monospace;">x = 3 </div> <small><i>(note the spaces around the '=')</i></small></li>
45
 
      <li><div style="font-family: Courier New,Courier,monospace;">echo $x</div></li>
46
 
      <li><div style="font-family: Courier New,Courier,monospace;">echo Another number: (+ $x (* 5 10)) </div><small><i>(note the prefix notation, that is the same as <b>$x + (5*10)</b>)</i></small></li>
47
 
      <li><div style="font-family: Courier New,Courier,monospace;">if (> $x 2) [ echo "x is bigger than 2" ] [ echo "x is not bigger than 2" ]</div></li>
48
 
    </ul>
49
 
    Check out the CubeScript <a href="http://sauerbraten.org/docs/config.html#cubescript">docs</a> or
50
 
    <a href="http://cube.wikispaces.com/Cubescript+Tutorial">tutorial</a>
51
 
    for more (but, they mainly talk about using CubeScript in Sauerbraten itself - much like most
52
 
    JavaScript tutorials talk about using JavaScript in a web browser).
53
 
  </p>
54
 
  <hr>
55
 
  <!-- Call the cubescript engine's execute() function -->
56
 
  <form onsubmit="execute(the_input.value); the_input.value = ''; return false">
57
 
    <b>Enter some CubeScript</b>:
58
 
    <input type="text" id="the_input">
59
 
    <input type="submit" value="execute">
60
 
  </form>
61
 
  <hr>
62
 
  <div id="output" style="font-family: Courier New,Courier,monospace;"></div>
63
 
</body>
64
 
</html>
65