<!DOCTYPE html>
<html>
<!--
Copyright (c) 2010 The Native Client Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>NaTcl : Tcl in Nacl</title>
<script type="text/javascript">
// NaTcl -- JS glue
var tclModule = null; // our singleton Tcl interp
var canvas = null;
var context = null;
var canvcoords = [];
// give it global scope. will be regen'd by canv code.
function repaint() {}
// debugging stuff
function printf(s)
{
// I like debugging to stderr instead of console.log,
// because when things go wrong, the JS console is not
// alays reachable.
tclModule.eval('printf {'+s+'}');
}
function ljoin()
{
// yeah. 'arguments' is 'similar to an array but not quite'
// that's why I think JS has no soul.
return Array.prototype.slice.call(arguments).join("\n");
}
// --- tclDo is the main JS-Tcl trampoline.
//
// Its job is to pass a Tcl string to [eval] (through naclwrap, see
// init.nacl), and then take back the result as JS and eval() it.
// It also detects errors in the latter eval() and pipes them back
// to [bgerror].
tclReportError = "";
function tclDo(s) {
//printf("do:"+s);
try {
t = tclModule.eval("naclwrap {"+s+"}");
//printf("ret:"+t);
eval(t);
} catch(err) {
//printf("JS-err:"+err);
tclReportError="bgerror {"+err+" -- while doing: "+t+"}";
setTimeout('tclDo(tclReportError)',0);
}
}
// --- tclsource starts an XHR, and calls the given 'tcb' (Tcl
// --- Callback) on completion. A catchable Tcl-level error is raised
// --- in case of not-200. Used by [source].
function tclsource(url,tcb) {
//printf('tclsource');
xs = new XMLHttpRequest();
xs.open("GET",url,true);
xs.send(null);
xs.onreadystatechange = function() {
//printf("XHR-source:"+xs.readyState);
if (xs.readyState==4)
{
if (xs.status==200) {
tclDo(tcb+" {"+xs.responseText+"}");
} else {
tclDo(tcb+" {error \"Can't source -- "+xs.statusText+"\"}");
}
}
};
}
// ---------- GUI and standard NaCl-loading machinery --------
var statusField = null;
modstatus = 'Loading...';
function updateStatus(opt_message) {
if (statusField) {
statusField.innerHTML = modstatus;
}
}
function moduleDidLoad() {
tclModule = document.getElementById('tcl');
updateStatus('NaTcl Loaded ; Fetching and running !');
tclDo('coroutine main_coro source balls.natcl');
}
// If the page loads before the Native Client module loads, then set the
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
function pageDidLoad() {
statusField = document.getElementById('modstatus');
canvas=document.getElementById('canvas');
context=canvas.getContext("2d");
if (tclModule == null) {
updateStatus('Loading Nacl...');
} else {
// It's possible that the Native Client module onload event fired
// before the page's onload event. In this case, the status message
// will reflect 'SUCCESS', but won't be displayed. This call will
// display the current message.
updateStatus();
}
}
</script>
</head>
<body onload="pageDidLoad()">
<h1>NaTcl -- Native Client Tcl Module</h1>
<p>
<canvas id="canvas" width="576" height="300"></canvas>
<!-- Load the published .nexe. This includes the 'nacl' attribute which
shows how to load multi-architecture modules. Each entry in the "nexes"
object in the .nmf manifest file is a key-value pair: the key is the runtime
('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
To load the debug versions of your .nexes, set the 'nacl' attribute to the
_dbg.nmf version of the manifest file.
-->
<embed name="nacl_module"
id="tcl"
width=0 height=0
nacl="tcl.nmf"
type="application/x-nacl"
onload="moduleDidLoad();" />
</p>
<p>This is a NaTcl emulation of the "Google Balls" Javascript demo at <a href="http://www.html5canvastutorials.com/labs/html5-canvas-google-bouncing-balls/">http://www.html5canvastutorials.com/labs/html5-canvas-google-bouncing-balls/</a></p>
Status: <b><span id="modstatus">NO-STATUS</span></b>
<hr>
<p style="font-size : smaller;">
To run this demo, you need
<ul style="font-size : smaller;">
<li> An x86-family processor
<li> Chrome 10 or higher
<li> Enabled "Native Client" item in about:flags
<li> (if on Linux) the --no-sandbox command-line flag to Chrome
<li> if everything else fails, try the Nacl demos at <a href="http://code.google.com/chrome/nativeclient/docs/examples.html">http://code.google.com/chrome/nativeclient/docs/examples.html</a>
</ul>
</p>
</body>
</html>