diff --git a/src/core/org/luaj/lib/DebugLib.java b/src/core/org/luaj/lib/DebugLib.java index 606ec0f2..c63ec4d2 100644 --- a/src/core/org/luaj/lib/DebugLib.java +++ b/src/core/org/luaj/lib/DebugLib.java @@ -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]; } diff --git a/src/j2se/lua.java b/src/j2se/lua.java index 2f8ff0c4..77eac4ed 100644 --- a/src/j2se/lua.java +++ b/src/j2se/lua.java @@ -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); diff --git a/src/test/res/debuglib.lua b/src/test/res/debuglib.lua index 7626d409..a3e52a77 100644 --- a/src/test/res/debuglib.lua +++ b/src/test/res/debuglib.lua @@ -74,7 +74,7 @@ end print( 'h', h() ) local funs = { f, g, h } local names = { 'f', 'g', 'h' } -for i=1,3 do +for i=1,3 do local fun,name = funs[i],names[i] for index=0,10 do local s1,x1,y1 = pcall( debug.getupvalue, fun, index ) @@ -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') )