| 1 | <!doctype html> |
| 2 | <html lang="en-us"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 | <title>ChucK + JS => ChucKScript</title> |
| 7 | <link rel="stylesheet" href="../../css/editor.css"> |
| 8 | </head> |
| 9 | <body onresize="chuckEditor.resize();"> |
| 10 | <div> |
| 11 | <div id="program">// Globals 7: setting and getting ints[], floats[] |
| 12 | global int globalInts[5]; |
| 13 | global float globalFloats[5]; |
| 14 | 2 => globalInts[1]; |
| 15 | 4.5 => globalFloats[3]; |
| 16 | |
| 17 | 3 => globalInts["hi"]; |
| 18 | 5.5 => globalFloats["hello"]; |
| 19 | global Event windsOfChange; |
| 20 | |
| 21 | <<< globalInts[1], globalFloats[3], globalInts["hi"], globalFloats["hello"] >>>; |
| 22 | windsOfChange.signal(); |
| 23 | 0.5::second => now; |
| 24 | <<< globalInts[1], globalFloats[3], globalInts["hi"], globalFloats["hello"] >>>; |
| 25 | <<< globalInts["bye"], globalFloats["goodbye"] >>>; |
| 26 | <<< globalInts[7], globalFloats[7] >>>; |
| 27 | windsOfChange.signal(); |
| 28 | </div> |
| 29 | </div> |
| 30 | <div class="buttons"> |
| 31 | <button class="chuckButton" id="startChuck" disabled="disabled">Start ChucK</button> |
| 32 | <button class="chuckButton" id="compileButton" disabled="disabled">Compile and Run</button> |
| 33 | <button class="chuckButton" id="replaceButton" disabled="disabled">Replace</button> |
| 34 | <button class="chuckButton" id="removeButton" disabled="disabled">Remove</button> |
| 35 | <button class="chuckButton" id="clearButton" disabled="disabled">Clear VM and Globals</button> |
| 36 | <button class="chuckButton" id="micButton" disabled="disabled">Enable Microphone</button> |
| 37 | <button class="chuckButton" id="fileFormButton">Show File Uploader</button> |
| 38 | </div> |
| 39 | <div id="fileForm" class="hidden"> |
| 40 | <p>File name to use in ChucK: <input type="text" id="uploadFilename"></p> |
| 41 | <p>Local file to upload: <input type="file" id="uploadFile" name="uploadFile"></p> |
| 42 | <p><button class="chuckButton" id="fileButton" disabled="disabled">Upload File to Virtual File System</button></p> |
| 43 | </div> |
| 44 | <div> |
| 45 | <textarea id="output"></textarea> |
| 46 | <div id="shreds"> |
| 47 | <table id="shredstable"> |
| 48 | <col width="60px"> |
| 49 | <col width="1*"> |
| 50 | <col width="50px"> |
| 51 | <col width="60px"> |
| 52 | <tr><th>shred</th><th>code</th><th>time</th><th>remove</th> |
| 53 | </table> |
| 54 | </div> |
| 55 | <div class="clearfix"></div> |
| 56 | </div> |
| 57 | <script type="text/javascript" src="../../js/ace-min-noconflict/ace.js" charset="utf-8"></script> |
| 58 | <script type="text/javascript" src="../../js/editor.js"></script> |
| 59 | <script type="text/javascript" src="../../js/defer.js"></script> |
| 60 | <script> |
| 61 | // override |
| 62 | var whereIsChuck = "../../js"; |
| 63 | </script> |
| 64 | <script type="text/javascript" src="../../js/webchuck_host.js"></script> |
| 65 | <script type="text/javascript" src="../../js/host.js"></script> |
| 66 | <script> |
| 67 | theChuckReady.then( function() { |
| 68 | // compile it for this test without waiting for the user to click button |
| 69 | // just to make sure the global Event exists |
| 70 | theChuck.runCode( "global Event windsOfChange;" ).then( function( shred ) |
| 71 | { |
| 72 | // so we can do this after |
| 73 | theChuck.listenForEventOnce( "windsOfChange", function() |
| 74 | { |
| 75 | |
| 76 | theChuck.setIntArray( "globalInts", [0, 1, 2, 3, 4, 5, 6, 7] ); |
| 77 | theChuck.setIntArrayValue( "globalInts", 1, 50 ); |
| 78 | theChuck.setAssociativeIntArrayValue( "globalInts", "hi", 51 ); |
| 79 | theChuck.setAssociativeIntArrayValue( "globalInts", "bye", 52 ); |
| 80 | theChuck.setFloatArray( "globalFloats", [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5] ); |
| 81 | theChuck.setFloatArrayValue( "globalFloats", 3, 50.5 ); |
| 82 | theChuck.setAssociativeFloatArrayValue( "globalFloats", "hello", 51.5 ); |
| 83 | theChuck.setAssociativeFloatArrayValue( "globalFloats", "goodbye", 52.5 ); |
| 84 | |
| 85 | theChuck.listenForEventOnce( "windsOfChange", function() |
| 86 | { |
| 87 | theChuck.getIntArrayValue( "globalInts", 1 ).then( function( result ) |
| 88 | { |
| 89 | chuckPrint( "the gotten global int is ", result ); |
| 90 | }); |
| 91 | theChuck.getAssociativeIntArrayValue( "globalInts", "hi" ).then( function( result ) |
| 92 | { |
| 93 | chuckPrint( "the gotten global associative int is ", result ); |
| 94 | }); |
| 95 | theChuck.getFloatArrayValue( "globalFloats", 3 ).then( function( result ) |
| 96 | { |
| 97 | chuckPrint( "the gotten global float is ", result ); |
| 98 | }); |
| 99 | theChuck.getAssociativeFloatArrayValue( "globalFloats", "hello" ).then( function( result ) |
| 100 | { |
| 101 | chuckPrint( "the gotten global associative float is ", result ); |
| 102 | }); |
| 103 | theChuck.getIntArray( "globalInts" ).then( function( result ) |
| 104 | { |
| 105 | chuckPrint( "the gotten int array is ", result ); |
| 106 | }); |
| 107 | theChuck.getFloatArray( "globalFloats" ).then( function( result ) |
| 108 | { |
| 109 | chuckPrint( "the gotten float array is ", result ); |
| 110 | }); |
| 111 | } ); |
| 112 | } ); |
| 113 | }); |
| 114 | }); |
| 115 | </script> |
| 116 | </body> |
| 117 | </html> |
| 118 | |
| 119 |