Let getinfo return without error when level extends beyond call stack
This commit is contained in:
@@ -208,6 +208,10 @@ public class DebugLib extends LFunction {
|
||||
String what = vm.optstring(3, "nSluf");
|
||||
if ( vm.isnumber(2) ) {
|
||||
ci = this.getcallinfo(vm, threadVm, vm.tointeger(2));
|
||||
if ( ci == null ) {
|
||||
vm.resettop();
|
||||
return;
|
||||
}
|
||||
closure = ci.closure;
|
||||
} else {
|
||||
func = vm.checkfunction(2);
|
||||
@@ -354,8 +358,10 @@ public class DebugLib extends LFunction {
|
||||
|
||||
private CallInfo getcallinfo(LuaState vm, LuaState threadVm, int level) {
|
||||
--level ; // level 0 is the debug function itself
|
||||
if ( level < 0 || level > threadVm.cc )
|
||||
vm.error("level out of range");
|
||||
if ( level > threadVm.cc )
|
||||
return null;
|
||||
if ( level < 0 )
|
||||
level = 0;
|
||||
int cc = threadVm.cc-level;
|
||||
return threadVm.calls[cc];
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.luaj.compiler.LuaC;
|
||||
import org.luaj.lib.DebugLib;
|
||||
import org.luaj.platform.J2sePlatform;
|
||||
import org.luaj.vm.LFunction;
|
||||
import org.luaj.vm.Lua;
|
||||
@@ -62,6 +63,7 @@ public class lua {
|
||||
Platform.setInstance(new J2sePlatform());
|
||||
LuaC.install();
|
||||
LuaState vm = Platform.newLuaState();
|
||||
DebugLib.install(vm);
|
||||
|
||||
// process args
|
||||
boolean interactive = (args.length == 0);
|
||||
|
||||
@@ -153,11 +153,14 @@ function test()
|
||||
x = x - 1
|
||||
print( '---' )
|
||||
printinfo( 'debug.getinfo(1)', debug.getinfo(1) )
|
||||
printinfo( 'debug.getinfo(1,"")', debug.getinfo(1, "") )
|
||||
printinfo( 'debug.getinfo(1,"l")', debug.getinfo(1, "l") )
|
||||
printinfo( 'debug.getinfo(1,"fL")', debug.getinfo(1, "fL") )
|
||||
printinfo( 'debug.getinfo(2)', debug.getinfo(2) )
|
||||
printinfo( 'debug.getinfo(2,"l")', debug.getinfo(2, "l") )
|
||||
printinfo( 'debug.getinfo(2,"fL")', debug.getinfo(2, "fL") )
|
||||
printinfo( 'debug.getinfo(10,"")', pcall( debug.getinfo, 10, "" ) )
|
||||
printinfo( 'debug.getinfo(-10,"")', pcall( debug.getinfo, -10, "" ) )
|
||||
--[[
|
||||
for i=1,3 do
|
||||
printinfo( 'debug.traceback("msg")', debug.traceback('msg') )
|
||||
|
||||
Reference in New Issue
Block a user