use of org.luaj.vm2.log.LuaPrint in project LuaViewSDK by alibaba.
the class LuaPrint method buildState.
/**
* Print the state of a {@link LuaClosure} that is being executed
*
* @param cl the {@link LuaClosure}
* @param pc the program counter
* @param stack the stack of {@link LuaValue}
* @param top the top of the stack
* @param varargs any {@link Varargs} value that may apply
*/
public LuaPrint buildState(LuaClosure cl, int pc, LuaValue[] stack, int top, Varargs varargs) {
// print opcode into buffer
StringBuffer previous = ps;
ps = new StringBuffer();
buildOpCode(cl.p, pc);
LogUtil.i(ps);
ps = previous;
format(ps.toString(), 50);
// print stack
ps.append('[');
for (int i = 0; i < stack.length; i++) {
LuaValue v = stack[i];
if (v == null)
ps.append(STRING_FOR_NULL);
else
switch(v.type()) {
case LuaValue.TSTRING:
LuaString s = v.checkstring();
ps.append(s.length() < 48 ? s.tojstring() : s.substring(0, 32).tojstring() + "...+" + (s.length() - 32) + "b");
break;
case LuaValue.TFUNCTION:
ps.append(v.tojstring());
break;
case LuaValue.TUSERDATA:
Object o = v.touserdata();
if (o != null) {
String n = o.getClass().getName();
n = n.substring(n.lastIndexOf('.') + 1);
ps.append(n + ": " + Integer.toHexString(o.hashCode()));
} else {
ps.append(v.toString());
}
break;
default:
ps.append(v.tojstring());
}
if (i + 1 == top)
ps.append(']');
ps.append(" | ");
}
ps.append(varargs);
ps.append("\n");
return this;
}