Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Commit

Permalink
Fixes #11
Browse files Browse the repository at this point in the history
I wasn't calling .eval: meaning it was probably called multiple times.
  • Loading branch information
SquidDev committed Feb 17, 2016
1 parent 6f5048c commit 1f512dc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.squiddev.luaj.luajc.function.FunctionExecutor;
import org.squiddev.luaj.luajc.function.FunctionWrapper;
import org.squiddev.luaj.luajc.function.executors.FallbackExecutor;
import org.squiddev.luaj.luajc.utils.AsmUtils;

public class JavaLoader extends ClassLoader {
/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public FunctionExecutor include(ProtoInfo info) {
}

protected Class<?> defineClass(String className, byte[] bytes) {
// if (options.verify) AsmUtils.validateClass(bytes, this);
if (options.verify) AsmUtils.validateClass(bytes, this);
return defineClass(className, bytes, 0, bytes.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Subclass of {@link LuaFunction} common to LuaJC compiled functions.
*/
public class FunctionWrapper extends BasicLuaFunction implements IGetPrototype {
public final class FunctionWrapper extends BasicLuaFunction implements IGetPrototype {
public final ProtoInfo info;
public final Prototype prototype;

Expand Down Expand Up @@ -51,6 +51,11 @@ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {

@Override
public Varargs invoke(Varargs args) {
return onInvoke(args).eval();
}

@Override
public Varargs onInvoke(Varargs args) {
return info.executor.execute(this, args);
}
}
9 changes: 7 additions & 2 deletions src/main/java/org/squiddev/luaj/luajc/utils/AsmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;

Expand Down Expand Up @@ -92,13 +93,17 @@ public static void validateClass(byte[] bytes, ClassLoader loader) {
validateClass(new ClassReader(bytes), loader);
}

public static void dump(byte[] bytes) {
public static void dump(byte[] bytes, OutputStream out) {
ClassReader reader = new ClassReader(bytes);
PrintWriter printWriter = new PrintWriter(System.out, true);
PrintWriter printWriter = new PrintWriter(out, true);

reader.accept(new TraceClassVisitor(printWriter), 0);
}

public static void dump(byte[] bytes) {
dump(bytes, System.out);
}


public static void writeSuperConstructor(MethodVisitor visitor, String name) {
visitor.visitVarInsn(ALOAD, 0);
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/org/squiddev/luaj/luajc/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ public class CompilerTest {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> getLua() {
return Arrays.asList(new Object[][]{
{"NForLoop"},
{"WhileLoop"},
{"DoBlock"},
{"Function"},
{"Upvalues"},
{"Recursive"},
{"Error"},
{"BranchUpvalue"},
{"BranchUpvalue2"},
{"RecursiveTrace"},
{"TailCall"},
{"StringDump"},
{"DebugInfo"},
{"DoBlock"},
{"EdgeCases"},
{"Error"},
{"Function"},
{"LoadBytecode"},
{"DebugInfo"},
{"NForLoop"},
{"NilCallReturn"},
{"Recursive"},
{"RecursiveTrace"},
{"SetFEnv"},
{"StringDump"},
{"TailCall"},
{"TailRecursion"},
{"UpvalueArgument"},
{"NilCallReturn"},
{"Upvalues"},
{"WhileLoop"},

{"fragment/ForLoopParamUpvalues"},
{"fragment/VarVarargsUseArg"},
Expand Down

0 comments on commit 1f512dc

Please sign in to comment.