Running Gacela programs in the browser (rectification)

Sometimes I have to stick a potato in my mouth before saying anything. Or take a potato in each hand before blogging anything.

In previous post about loading files with javascript, I said that it was not possible with Ajax, it was necessary to use iframes, etc, etc … Filthy Lie! Of course you can, and is much easier.

The code for loadinga Lisp program, compile it and run it would be:

<html>
    <head>
        <script type="text/javascript" src="lisp2js.js"></script>
        <script id="head_js" type="text/javascript"></script>
        <script type="text/javascript">
            function load_file (file) {
                var req = new XMLHttpRequest();
                req.open('GET', file, false);
                req.send(null);
                if (req.status == 200) {
                    var lisp_code = req.responseText;
                    var js_code = string2js(lisp_code);
                    document.getElementById('head_js').text = js_code;
                }
            }
        </script>
    </head>

    <body onLoad="load_file('my_program.lisp'); init();">
    </body>
</html>

This would be the synchronous version, but it can also be done asynchronously. You can see more examples in Using XMLHttpRequest.

Advertisement
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Running Gacela programs in the browser (rectification)

  1. Pingback: Running Gacela programs in the browser | Between parentheses

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s