Improve compatibility with lua 5.2.

This commit is contained in:
James Roseborough
2012-10-13 15:07:14 +00:00
parent c921b033c5
commit bb540819b0
4 changed files with 25 additions and 16 deletions

View File

@@ -560,5 +560,10 @@ public class LuaClosure extends LuaFunction {
protected void setUpvalue(int i, LuaValue v) {
upValues[i].setValue(v);
}
public String name() {
return "<"+p.shortsource()+":"+p.linedefined+">";
}
}

View File

@@ -77,4 +77,11 @@ public class LuaFunction extends LuaValue {
String s = getClass().getName();
return s.substring(Math.max(s.lastIndexOf('.'),s.lastIndexOf('$'))+1);
}
/** Return a human-readable name for this function. Returns the last part of the class name by default.
* Is overridden by LuaClosure to return the source file and line, and by LibFunctions to return the name.
* @return common name for this function. */
public String name() {
return classnamestub();
}
}

View File

@@ -79,4 +79,13 @@ public class Prototype {
}
return null; /* not found */
}
public String shortsource() {
String name = source.tojstring();
if ( name.startsWith("@") || name.startsWith("=") )
name = name.substring(1);
else if ( name.startsWith("\033") )
name = "binary string";
return name;
}
}

View File

@@ -467,13 +467,13 @@ public class DebugLib extends OneArgFunction {
this.linedefined = p.linedefined;
this.lastlinedefined = p.lastlinedefined;
this.what = (this.linedefined == 0) ? "main" : "Lua";
this.short_src = DebugLib.shortsource(p);
this.short_src = p.shortsource();
} else {
this.source = "=[Java]";
this.linedefined = -1;
this.lastlinedefined = -1;
this.what = "Java";
this.short_src = f.classnamestub();
this.short_src = f.name();
}
}
}
@@ -598,9 +598,6 @@ public class DebugLib extends OneArgFunction {
ar.name = nw.name;
ar.namewhat = nw.namewhat;
}
} else {
ar.name = ci.previous.f.classnamestub();
ar.namewhat = "Java";
}
}
if (ar.namewhat == null) {
@@ -635,7 +632,7 @@ public class DebugLib extends OneArgFunction {
this.stack = stack;
}
public String shortsource() {
return f.isclosure()? DebugLib.shortsource(f.checkclosure().p): "[Java]";
return f.isclosure()? f.checkclosure().p.shortsource(): "[Java]";
}
void set(LuaFunction function) {
this.f = function;
@@ -675,7 +672,7 @@ public class DebugLib extends OneArgFunction {
}
String sourceline() {
if ( !f.isclosure() ) return f.tojstring();
return DebugLib.shortsource(f.checkclosure().p) + ":" + currentline();
return f.checkclosure().p.shortsource() + ":" + currentline();
}
private int linedefined() {
return f.isclosure()? f.checkclosure().p.linedefined: -1;
@@ -696,15 +693,6 @@ public class DebugLib extends OneArgFunction {
return null;
}
public static String shortsource(Prototype p) {
String name = p.source.tojstring();
if ( name.startsWith("@") || name.startsWith("=") )
name = name.substring(1);
else if ( name.startsWith("\033") )
name = "binary string";
return name;
}
static void lua_assert(boolean x) {
if (!x) throw new RuntimeException("lua_assert failed");
}