From 447c7f98506292b2746e318edf5e161c72e9fc30 Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Fri, 5 Oct 2012 04:26:25 +0000 Subject: [PATCH] Let generated code have class names that match variable names used in function creation. --- src/jse/lua.java | 19 ++++--- src/jse/luajc.java | 6 +-- src/jse/org/luaj/vm2/luajc/JavaGen.java | 8 +-- src/jse/org/luaj/vm2/luajc/ProtoInfo.java | 66 ++++++++++++++++++++++- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/jse/lua.java b/src/jse/lua.java index b1ebdf45..eb4896e2 100644 --- a/src/jse/lua.java +++ b/src/jse/lua.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Luaj.org. All rights reserved. +* Copyright (c) 2009-2012 Luaj.org. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,24 +28,23 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.Vector; +import org.luaj.vm2.Globals; import org.luaj.vm2.LoadState; import org.luaj.vm2.Lua; -import org.luaj.vm2.LuaClosure; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import org.luaj.vm2.Print; import org.luaj.vm2.Varargs; -import org.luaj.vm2.lib.DebugLib; import org.luaj.vm2.lib.jse.JsePlatform; import org.luaj.vm2.luajc.LuaJC; /** - * lua command for use in java se environments. + * lua command for use in JSE environments. */ public class lua { - private static final String version = Lua._VERSION + "Copyright (c) 2012 Luaj.org.org"; + private static final String version = Lua._VERSION + " Copyright (c) 2012 Luaj.org.org"; private static final String usage = "usage: java -cp luaj-jse.jar lua [options] [script [args]].\n" + @@ -56,6 +55,7 @@ public class lua { " -v show version information\n" + " -b use luajc bytecode-to-bytecode compiler (requires bcel on class path)\n" + " -n nodebug - do not load debug library by default\n" + + " -p print the prototype\n" + " -- stop handling options\n" + " - execute stdin and stop handling options"; @@ -64,7 +64,8 @@ public class lua { System.exit(-1); } - private static LuaValue _G; + private static Globals _G; + private static boolean print = false; public static void main( String[] args ) throws IOException { @@ -73,7 +74,6 @@ public class lua { boolean versioninfo = false; boolean processing = true; boolean nodebug = false; - boolean print = false; boolean luajc = false; Vector libs = null; try { @@ -110,6 +110,9 @@ public class lua { case 'n': nodebug = true; break; + case 'p': + print = true; + break; case '-': if ( args[i].length() > 2 ) usageExit(); @@ -190,6 +193,8 @@ public class lua { } finally { script.close(); } + if (print && c.isclosure()) + Print.print(c.checkclosure().p); Varargs scriptargs = setGlobalArg(chunkname, args, firstarg, _G); c.invoke( scriptargs ); } catch ( Exception e ) { diff --git a/src/jse/luajc.java b/src/jse/luajc.java index 5252af42..e4624c45 100644 --- a/src/jse/luajc.java +++ b/src/jse/luajc.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Luaj.org. All rights reserved. +* Copyright (c) 2009-2012 Luaj.org. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -56,8 +56,8 @@ public class luajc { System.exit(-1); } - private String srcdir = null; - private String destdir = null; + private String srcdir = "."; + private String destdir = "."; private boolean genmain = false; private boolean recurse = false; private boolean verbose = false; diff --git a/src/jse/org/luaj/vm2/luajc/JavaGen.java b/src/jse/org/luaj/vm2/luajc/JavaGen.java index 4e2d2bd6..67a892e3 100644 --- a/src/jse/org/luaj/vm2/luajc/JavaGen.java +++ b/src/jse/org/luaj/vm2/luajc/JavaGen.java @@ -58,16 +58,12 @@ public class JavaGen { int n = pi.subprotos.length; inners = new JavaGen[n]; for ( int i=0; i 0 ) builder.dup(); diff --git a/src/jse/org/luaj/vm2/luajc/ProtoInfo.java b/src/jse/org/luaj/vm2/luajc/ProtoInfo.java index 1b1ab08d..b983b412 100644 --- a/src/jse/org/luaj/vm2/luajc/ProtoInfo.java +++ b/src/jse/org/luaj/vm2/luajc/ProtoInfo.java @@ -2,8 +2,11 @@ package org.luaj.vm2.luajc; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.Hashtable; +import java.util.Vector; import org.luaj.vm2.Lua; +import org.luaj.vm2.LuaString; import org.luaj.vm2.Print; import org.luaj.vm2.Prototype; import org.luaj.vm2.Upvaldesc; @@ -411,12 +414,13 @@ public class ProtoInfo { int n = code.length; // propogate to inner prototypes + String[] names = findInnerprotoNames(); for ( int pc=0; pc