Relocate some debug-related methods.

This commit is contained in:
James Roseborough
2009-04-05 17:34:48 +00:00
parent e9847bb70d
commit f51fac919e
8 changed files with 50 additions and 14 deletions

View File

@@ -298,23 +298,11 @@ public class DebugLib extends LFunction {
return null;
}
private LString getlocalname (LPrototype f, int local_number, int pc) {
int i;
for (i = 0; i<f.locvars.length && f.locvars[i].startpc <= pc; i++) {
if (pc < f.locvars[i].endpc) { /* is variable active? */
local_number--;
if (local_number == 0)
return f.locvars[i].varname;
}
}
return null; /* not found */
}
private LString findlocal(LuaState vm, int cc, int n) {
CallInfo ci = vm.calls[cc];
LString name;
LPrototype fp = ci.closure.p;
if ( fp!=null && (name = getlocalname(fp, n, ci.pc-1)) != null)
if ( fp!=null && (name = fp.getlocalname(n, ci.pc-1)) != null)
return name;
return null;
}

View File

@@ -40,4 +40,8 @@ public class CallInfo {
this.pc = 0;
}
public boolean isLua() {
return true;
}
}

View File

@@ -59,4 +59,9 @@ public class LClosure extends LFunction {
return env;
}
/** Returns true if this is a lua closure, false otherwise */
public boolean isClosure() {
return true;
}
}

View File

@@ -97,4 +97,8 @@ public class LNumber extends LValue {
luaAsString().luaConcatTo( baos );
}
/** Returns true if this is or can be made into a number */
public boolean isNumber() {
return true;
}
}

View File

@@ -52,4 +52,21 @@ public class LPrototype {
public int is_vararg;
public int maxstacksize;
/** Get the name of a local variable.
*
* @param number the local variable number to look up
* @param pc the program counter
* @return the name, or null if not found
*/
public LString getlocalname(int number, int pc) {
int i;
for (i = 0; i<locvars.length && locvars[i].startpc <= pc; i++) {
if (pc < locvars[i].endpc) { /* is variable active? */
number--;
if (number == 0)
return locvars[i].varname;
}
}
return null; /* not found */
}
}

View File

@@ -456,4 +456,10 @@ public class LString extends LValue {
baos.write( m_bytes, m_offset, m_length );
}
/** Returns true if this is or can be made into a number */
public boolean isNumber() {
return ! this.luaToNumber().isNil();
}
}

View File

@@ -350,4 +350,14 @@ public class LValue {
public boolean isUserData() {
return false;
}
/** Returns true if this is or can be made into a number */
public boolean isNumber() {
return false;
}
/** Returns true if this is a lua closure, false otherwise */
public boolean isClosure() {
return false;
}
}

View File

@@ -2524,4 +2524,6 @@ public class LuaState extends Lua {
top = oldtop;
}
}
}