From dc0be9b15a9a35bd4a01b43bbb32182a3325363b Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Wed, 31 Mar 2010 04:15:09 +0000 Subject: [PATCH] Add doc for bytecode generator. --- README.html | 65 +++++++++++++++++++++++++++++++++++++++------- build.xml | 9 ------- src/jse/luajc.java | 2 +- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/README.html b/README.html index 4ece1a49..d91ae8c9 100644 --- a/README.html +++ b/README.html @@ -17,7 +17,7 @@ Getting Started with LuaJ -James Roseborough, Ian Farmer, Version 1.9.50 +James Roseborough, Ian Farmer, Version 1.9.53

Copyright © 2007-2009 Luaj.org. @@ -42,7 +42,7 @@ Freely available under the terms of the

-This is a development release for a planned luaj 2.0. The most recent stable release is 1.0.1 +This is a development release for a planned luaj 2.0. The most recent stable release is 1.0.2 @@ -54,7 +54,7 @@ This is a development release for a planned luaj 2.0. The most recent stable re From the main distribution directory line type:

-	java -cp lib/luaj-jse-1.9.50.jar lua examples/lua/hello.lua
+	java -cp lib/luaj-jse-1.9.53.jar lua examples/lua/hello.lua
 

@@ -99,7 +99,7 @@ A simple example may be found in

-You must include the library lib/luaj-jse-1.9.50.jar in your class path. +You must include the library lib/luaj-jse-1.9.53.jar in your class path.

Run a script in a MIDlet

@@ -128,7 +128,7 @@ A simple example may be found in

-You must include the library lib/luaj-jme-1.9.50.jar in your midlet jar. +You must include the library lib/luaj-jme-1.9.53.jar in your midlet jar. They can be obfuscated if desired.

Including the compiler

@@ -163,7 +163,7 @@ The standard use of JSR-233 scripting engines may be used: All standard aspects of script engines including compiled statements should be supported.

-You must include the library lib/luaj-jse-1.9.50.jar in your class path. +You must include the library lib/luaj-jse-1.9.53.jar in your class path.

A working example may be found in @@ -171,6 +171,47 @@ A working example may be found in examples/jse/ScriptEngineSample.java +

Compile lua to Java bytecode using luajc

+ +

+A code generator that compiles lua to java bytecode base on the +bcel library is now included. + +

+To use it at runtime, the tool "lua" has an option "-j" to compile into java bytecode. + +

+	java -cp luaj-jse-1.9.53.jar;lib/bcel-5.2.jar lua -j examples/lua/hello.lua
+
+ +

+To compile lua files into Java in advance, the tool "luajc" is provided: + +

+	cp examples/lua/hello.lua .
+	java -cp luaj-jse-1.9.53.jar;lib/bcel-5.2.jar luajc hello.lua
+	ls -l hello.class
+
+ +You should see a class file of 906 bytes or so. A version of the bcel +library must be in your class path for code generation to work. +The ant script contains a target for fetching bcel v 5.2: + +
+	ant bcel-lib
+
+ +

+Files compiled into java in this way can be run via Java class loading, without the bcel libraries +(generated class files must be in your class path): + +

+	java -cp luaj-jse-1.9.53.jar;. lua -l hello
+
+ +The current bytecode generator produces a separate class file for each prototype, +and generated class files do not work properly with module() or setfenv(). +

2 - Concepts

@@ -283,7 +324,7 @@ The following lua script will open a swiing frame on Java SE:

See a longer sample in src/test/res/swingapp.lua for details, or try running it using:

-	java -cp lib/luaj-jse-1.9.50.jar lua src/test/res/swingapp.lua
+	java -cp lib/luaj-jse-1.9.53.jar lua src/test/res/swingapp.lua
 

@@ -317,7 +358,7 @@ These tests are used for to produce code coverage statistics using build-coverag

5 - Downloads

Downloads and Project Pages

-Downloads for version 1.0.1 are currently hosted on SourceForge. +Downloads for version 1.0.2 are currently hosted on SourceForge. Downloads of built packages for 2.0 are not yet available. Sources are available via sourceforge.net
@@ -336,5 +377,11 @@ and LuaForge: Main changes by version:
- + +
  1.9.50Most interpreter features are working. Initial port of all libraries has been done.
  1.9.53 +Most interpreter features are working. Initial port of all libraries has been done. +
  1.9.53 +All unit tests that have been included in the project pass. +Compile-to-Java based on bcel 5.2 is working. +
diff --git a/build.xml b/build.xml index 5a82b2fe..2e288e47 100644 --- a/build.xml +++ b/build.xml @@ -8,15 +8,6 @@ - - diff --git a/src/jse/luajc.java b/src/jse/luajc.java index f1d9eabd..2077dcb4 100644 --- a/src/jse/luajc.java +++ b/src/jse/luajc.java @@ -41,7 +41,7 @@ public class luajc { private static final String version = Lua._VERSION + "Copyright (C) 2009 luaj.org"; private static final String usage = - "usage: java -cp luaj-jse.jar,antlr-3.1.3.jar luajc [options] [filenames].\n" + + "usage: java -cp luaj-jse.jar,bcel-5.2.jar luajc [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -o name output to file 'name' (default is \"luac.out\")\n" +