From de9c967ac506d13dc0fe339178c44339686f881f Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Sun, 25 Apr 2010 05:35:24 +0000 Subject: [PATCH] Fix midlet example including luajc-compiled scripts --- build-midlet.xml | 49 +++++++++++--- examples/jme/SampleMIDlet.java | 2 +- src/jse/luajc.java | 118 +++++++++++++++------------------ 3 files changed, 96 insertions(+), 73 deletions(-) diff --git a/build-midlet.xml b/build-midlet.xml index 0b641693..a5e4667f 100644 --- a/build-midlet.xml +++ b/build-midlet.xml @@ -1,5 +1,5 @@ - + @@ -16,42 +16,75 @@ - + + + + + + + + + + + + + + + + + + + + + - + + + + - + + + - - + + + + + + - - + + + + + + diff --git a/examples/jme/SampleMIDlet.java b/examples/jme/SampleMIDlet.java index 6db80ddc..df2f4684 100644 --- a/examples/jme/SampleMIDlet.java +++ b/examples/jme/SampleMIDlet.java @@ -22,7 +22,7 @@ public class SampleMIDlet extends MIDlet { // create an environment to run in LuaC.install(); LuaValue _G = JmePlatform.standardGlobals(); - _G.get("dofile").call( LuaValue.valueOf(script) ); + _G.get("require").call( LuaValue.valueOf(script) ); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { diff --git a/src/jse/luajc.java b/src/jse/luajc.java index 2fd3380c..ea83018f 100644 --- a/src/jse/luajc.java +++ b/src/jse/luajc.java @@ -24,18 +24,16 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Vector; import org.luaj.vm2.Lua; import org.luaj.vm2.compiler.DumpState; import org.luaj.vm2.luajc.LuaJC; - - /** - * Compiler for lua files to compile lua sources into java sources. + * Compiler for lua files to compile lua sources or lua binaries into java classes. */ public class luajc { private static final String version = Lua._VERSION + "Copyright (C) 2009 luaj.org"; @@ -44,9 +42,9 @@ public class luajc { "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" + - " -p parse only\n" + - " -s strip debug information\n" + + " -s source directory\n" + + " -d destination directory\n" + + " -n no debug information (strip debug)\n" + " -e little endian format for numbers\n" + " -i number format 'n', (n=0,1 or 4, default="+DumpState.NUMBER_FORMAT_DEFAULT+")\n" + " -v show version information\n" + @@ -57,13 +55,12 @@ public class luajc { System.exit(-1); } - private String output = "luacj.out"; - private boolean parseonly = false; + private String srcdir = null; + private String destdir = null; private boolean stripdebug = false; private boolean littleendian = false; private int numberformat = DumpState.NUMBER_FORMAT_DEFAULT; - private boolean versioninfo = false; - private boolean processing = true; + private boolean verbose = false; public static void main( String[] args ) throws IOException { new luajc( args ); @@ -73,23 +70,25 @@ public class luajc { // process args try { + Vector files = new Vector(); + // get stateful args for ( int i=0; i= args.length ) usageExit(); - output = args[i]; + srcdir = args[i]; break; - case 'p': - parseonly = true; + case 'd': + if ( ++i >= args.length ) + usageExit(); + destdir = args[i]; break; - case 's': + case 'n': stripdebug = true; break; case 'e': @@ -101,12 +100,7 @@ public class luajc { numberformat = Integer.parseInt(args[i].substring(2)); break; case 'v': - versioninfo = true; - break; - case '-': - if ( args[i].length() > 2 ) - usageExit(); - processing = false; + verbose = true; break; default: usageExit(); @@ -116,34 +110,28 @@ public class luajc { } // echo version - if ( versioninfo ) + if ( verbose ) { System.out.println(version); + System.out.println("srcdir: "+srcdir); + System.out.println("destdir: "+srcdir); + System.out.println("stripdebug: "+stripdebug); + System.out.println("littleendian: "+littleendian); + System.out.println("numberformat: "+numberformat); + System.out.println("files: "+files); + } - // open output file - OutputStream fos = new FileOutputStream( output ); - // process input files - try { - processing = true; - for ( int i=0; i