/docs/heclandjava.html
https://github.com/soundanny/hecl · HTML · 60 lines · 42 code · 18 blank · 0 comment · 0 complexity · 9562f03111aeb6d6fcc0bbe8938dd8bb MD5 · raw file
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Interfacing Hecl and Java</title><link rel="stylesheet" href="hecl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.1"><link rel="home" href="index.html" title="Hecl - The Mobile Scripting Language"><link rel="up" href="index.html" title="Hecl - The Mobile Scripting Language"><link rel="prev" href="kxml.getname.html" title="kxml.getname"><link rel="next" href="creating_new_hecl_commands.html" title="Creating new Hecl commands"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Interfacing Hecl and Java</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="kxml.getname.html"><img src="images/prev.png" alt="Prev"></a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="creating_new_hecl_commands.html"><img src="images/next.png" alt="Next"></a></td></tr></table></div><div class="section" title="Interfacing Hecl and Java"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="heclandjava"></a>Interfacing Hecl and Java</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="heclandjava.html#%0A%09id-1.7.3">Calling Hecl code from Java</a></span></dt><dt><span class="section"><a href="creating_new_hecl_commands.html">Creating new Hecl commands</a></span></dt><dt><span class="section"><a href="building_hecl.html">Building Hecl: Ant Targets</a></span></dt><dt><span class="section"><a href="hecl_javadocs.html">JavaDocs</a></span></dt></dl></div>
-
- <p>
- Hecl is not a replacement for Java, and is indeed meant to work hand in hand with Java. We
- attempt to make it as easy as possible to call Java from Hecl, via the creation of new Hecl
- commands that can call Java code, in addition to calling Hecl from Java, which is a matter of
- a few lines of code.
- </p>
- <div class="section" title="Calling Hecl code from Java"><div class="titlepage"><div><div><h3 class="title"><a name="id-1.7.3.1"></a>Calling Hecl code from Java</h3></div></div></div>
-
- <pre class="programlisting">
- import org.hecl.files.HeclFile;
- import org.hecl.Eval;
- import org.hecl.Interp;
- import org.hecl.Thing;
- import org.hecl.ListThing;
- import org.hecl.HeclException;
- ...
- try {
- /* First, create a new interpreter, and pass it a
- * mechanism to load resources with - in this case,
- * files. */
- Interp interp = new Interp();
- /* Add the files package */
- new HeclFile().loadModule(interp);
- /* Evaluate the file at args[0] */
- HeclFile.sourceFile(interp, args[0]);
- /* Evaluate some code in a string. */
- String helloworld = new String("puts {Hello, world!}");
- interp.eval(new Thing(helloworld));
- } catch (Exception e) {
- System.err.println(e);
- }
- </pre>
- <p>
- The above code first creates a new interpreter. Next, it
- instantiates the HeclFile system. This isn't part of the Hecl
- core, because some systems, like J2ME, may not have files. If
- you don't have files, you can still use
- <code class="methodname">interp.eval</code> to evaluate some code,
- which could come from whatever source you desire.
- </p>
- </div>
-
-
-
- </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="kxml.getname.html"><img src="images/prev.png" alt="Prev"></a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="creating_new_hecl_commands.html"><img src="images/next.png" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">kxml.getname </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a></td><td width="40%" align="right" valign="top"> Creating new Hecl commands</td></tr></table></div></body></html>