org.luaj.vm2.Print Java Examples

The following examples show how to use org.luaj.vm2.Print. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
void instr(int pc, Varargs v, int top) {
	this.pc = pc;
	this.v = v;
	this.top = top;
	if (TRACE)
		Print.printState(f.checkclosure(), pc, stack, top, v);
}
 
Example #2
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
void instr(int pc, Varargs v, int top) {
	this.pc = pc;
	this.v = v;
	this.top = top;
	if (TRACE)
		Print.printState(f.checkclosure(), pc, stack, top, v);
}
 
Example #3
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
void instr(int pc, Varargs v, int top) {
	this.pc = pc;
	this.v = v;
	this.top = top;
	if (TRACE)
		Print.printState(f.checkclosure(), pc, stack, top, v);
}
 
Example #4
Source File: TestLuaJ.java    From luaj with MIT License 5 votes vote down vote up
private static void print(Prototype p) {
	System.out.println("--- "+p);
	Print.printCode(p);
	if (p.p!=null)
		for ( int i=0,n=p.p.length; i<n; i++ )
			print( p.p[i] );
}
 
Example #5
Source File: TestLuaJC.java    From luaj with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	if (args.length > 0)
		filename = args[0];
	System.out.println("filename: "+filename);
	try {
		
		// create an environment to run in
		globals = JsePlatform.standardGlobals();

		// print the chunk as a closure, and pretty-print the closure.
		LuaValue f = globals.loadfile(filename).arg1();
		Prototype p = f.checkclosure().p;
		Print.print(p);

		// load into a luajc java-bytecode based chunk by installing the LuaJC compiler first
		if ( ! (args.length>0 && args[0].equals("nocompile")) ) {
			LuaJC.install(globals);
			f = globals.loadfile(filename).arg1();
		}

		// call with arguments
		Varargs v = f.invoke(LuaValue.NONE);
		
		// print the result
		System.out.println("result: "+v);

		// Write out the files.
		// saveClasses();
		
	} catch ( Throwable e ) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: AbstractUnitTests.java    From luaj with MIT License 5 votes vote down vote up
protected String protoToString(Prototype p) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    Print.ps = ps;
    new Print().printFunction(p, true);
    return baos.toString();
}
 
Example #7
Source File: ProtoInfo.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public String toString() {
	StringBuffer sb = new StringBuffer();
	
	// prototpye name
	sb.append( "proto '"+name+"'\n" );
	
	// upvalues from outer scopes
	for ( int i=0, n=(upvals!=null? upvals.length: 0); i<n; i++ )
		sb.append( " up["+i+"]: "+upvals[i]+"\n" );
	
	// basic blocks
	for ( int i=0; i<blocklist.length; i++ ) {
		BasicBlock b = blocklist[i];
		int pc0 = b.pc0;
		sb.append( "  block "+b.toString() );
		appendOpenUps( sb, -1 );
		
		// instructions
		for ( int pc=pc0; pc<=b.pc1; pc++ ) {

			// open upvalue storage
			appendOpenUps( sb, pc );
			
			// opcode
			sb.append( "     " );
			for ( int j=0; j<prototype.maxstacksize; j++ ) {
				VarInfo v = vars[j][pc];
				String u = (v==null? "": v.upvalue!=null? !v.upvalue.rw? "[C] ": (v.allocupvalue&&v.pc==pc? "[*] ": "[]  "): "    ");
				String s = v==null? "null   ": String.valueOf(v);
				sb.append( s+u);
			}
			sb.append( "  " );
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			PrintStream ops = Print.ps;
			Print.ps = new PrintStream(baos);
			try {
				Print.printOpCode(prototype, pc);
			} finally {
				Print.ps.close();
				Print.ps = ops;					
			}
			sb.append( baos.toString() );
			sb.append( "\n" );
		}
	}
	
	// nested functions
	for ( int i=0, n=subprotos!=null? subprotos.length: 0; i<n; i++ ) {
		sb.append( subprotos[i].toString() );
	}
	
	return sb.toString();
}
 
Example #8
Source File: ProtoInfo.java    From luaj with MIT License 4 votes vote down vote up
public String toString() {
	StringBuffer sb = new StringBuffer();
	
	// prototpye name
	sb.append( "proto '"+name+"'\n" );
	
	// upvalues from outer scopes
	for ( int i=0, n=(upvals!=null? upvals.length: 0); i<n; i++ )
		sb.append( " up["+i+"]: "+upvals[i]+"\n" );
	
	// basic blocks
	for ( int i=0; i<blocklist.length; i++ ) {
		BasicBlock b = blocklist[i];
		int pc0 = b.pc0;
		sb.append( "  block "+b.toString() );
		appendOpenUps( sb, -1 );
		
		// instructions
		for ( int pc=pc0; pc<=b.pc1; pc++ ) {

			// open upvalue storage
			appendOpenUps( sb, pc );
			
			// opcode
			sb.append( "     " );
			for ( int j=0; j<prototype.maxstacksize; j++ ) {
				VarInfo v = vars[j][pc];
				String u = (v==null? "": v.upvalue!=null? !v.upvalue.rw? "[C] ": (v.allocupvalue&&v.pc==pc? "[*] ": "[]  "): "    ");
				String s = v==null? "null   ": String.valueOf(v);
				sb.append( s+u);
			}
			sb.append( "  " );
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			PrintStream ops = Print.ps;
			Print.ps = new PrintStream(baos);
			try {
				Print.printOpCode(prototype, pc);
			} finally {
				Print.ps.close();
				Print.ps = ops;					
			}
			sb.append( baos.toString() );
			sb.append( "\n" );
		}
	}
	
	// nested functions
	for ( int i=0, n=subprotos!=null? subprotos.length: 0; i<n; i++ ) {
		sb.append( subprotos[i].toString() );
	}
	
	return sb.toString();
}