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

« back to all changes in this revision

Viewing changes to demos/lua.html

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <title>
 
4
    Emscripten: Lua
 
5
  </title>
 
6
  <link id="bespin_base" href="skywriter/"/>
 
7
  <script src="skywriter/BespinEmbedded.js"></script>
 
8
  <style type="text/css">
 
9
      .bespin {
 
10
          width: 80%;
 
11
          height: 30%;
 
12
      }
 
13
  </style>
 
14
  <script src="lua.js"></script>
 
15
  <script>
 
16
    // print function which the Lua engine will call
 
17
    var lines = [], printed = false;
 
18
 
 
19
    function print(text) {
 
20
      lines.push(text);
 
21
      printed = true;
 
22
    }
 
23
 
 
24
    function execute(text) {
 
25
      lines = [];
 
26
      printed = false;
 
27
 
 
28
      raw_argv[8] = Pointer_make(intArrayFromString(text), 0, ALLOC_STATIC); // leak!
 
29
      argv = Pointer_make(raw_argv, null);
 
30
      __Z7runargsP9lua_StatePPci(GLOBAL_L, argv, argc)
 
31
 
 
32
      if (!printed) {
 
33
        print('<small><i>(no output)</i></small>');
 
34
      }
 
35
 
 
36
      var element = document.getElementById('output');
 
37
      if (!element) return; // perhaps during startup
 
38
      element.innerHTML = lines.join('<br>') + '<hr>' + element.innerHTML;
 
39
    }
 
40
 
 
41
    var editor;
 
42
 
 
43
    function doRun() {
 
44
      args = ['-e', ''];
 
45
      run(args);
 
46
 
 
47
      setTimeout(function() { 
 
48
        if (!bespin.useBespin) setTimeout(arguments.callee, 10);
 
49
        bespin.useBespin(document.getElementById('the_input'), { "stealFocus":true, "syntax": "lua" }).then(function(env) {
 
50
          editor = env.editor;
 
51
        });
 
52
      }, 10);
 
53
    }
 
54
 
 
55
  </script>
 
56
</head>
 
57
<body onload="doRun(); document.getElementById('the_input').focus()">
 
58
  <p>
 
59
    This is the <a href="http://www.lua.org/">Lua</a> interpreter, compiled from C to JavaScript using <a href="http://emscripten.org">Emscripten</a>,
 
60
    running in your browser (without any plugins).
 
61
  </p>
 
62
  <p>
 
63
    <ul>
 
64
      <li>Most stuff should work, please report bugs if you find them!</li>
 
65
      <li>Note that this is an unoptimized build (see <a href="http://code.google.com/p/emscripten/issues/detail?id=8">issue 8</a>)</li>
 
66
      <li>The editor is <a href="https://mozillalabs.com/skywriter/">Skywriter</a>. Would be cool if someone made a syntax highlighting plugin for Lua...
 
67
    </ul>
 
68
  </p>
 
69
  <hr>
 
70
  <!-- Call Lua's execution function -->
 
71
  <form onsubmit="execute(editor.value); return false">
 
72
    <b>Enter some Lua</b>:
 
73
    <input type="submit" value="execute">
 
74
    <div id="the_input">
 
75
print("Hello world! This is: " .. _VERSION);
 
76
 
 
77
for i=1,5 do
 
78
  print("A number: " .. i)
 
79
end
 
80
    </div>
 
81
  </form>
 
82
  <hr>
 
83
  <div id="output" style="font-family: Courier New,Courier,monospace;"></div>
 
84
</body>
 
85
</html>
 
86