diff --git a/src/main/java/org/squiddev/cobalt/lib/DebugLib.java b/src/main/java/org/squiddev/cobalt/lib/DebugLib.java index d40b8c37..1ee26539 100644 --- a/src/main/java/org/squiddev/cobalt/lib/DebugLib.java +++ b/src/main/java/org/squiddev/cobalt/lib/DebugLib.java @@ -50,7 +50,8 @@ public final class DebugLib { private static final LuaString MAIN = valueOf("main"); private static final LuaString LUA = valueOf("Lua"); private static final LuaString C = valueOf("C"); - private static final LuaString C_SOURCE = valueOf("[C]"); + private static final LuaString C_SHORT_SOURCE = valueOf("[C]"); + private static final LuaString C_SOURCE = valueOf("=[C]"); public static final LuaString QMARK = valueOf("?"); private static final LuaString EXTERNAL_HOOK = valueOf("external hook"); @@ -191,11 +192,9 @@ private static Varargs getinfo(LuaState state, Varargs args) throws LuaError { info.rawset(LINEDEFINED, valueOf(p.lineDefined)); info.rawset(LASTLINEDEFINED, valueOf(p.lastLineDefined)); } else { - String shortName = function == null ? "nil" : function.debugName(); - LuaString name = valueOf("[C] " + shortName); info.rawset(WHAT, C); - info.rawset(SOURCE, name); - info.rawset(SHORT_SRC, C_SOURCE); + info.rawset(SOURCE, C_SOURCE); + info.rawset(SHORT_SRC, C_SHORT_SOURCE); info.rawset(LINEDEFINED, MINUSONE); info.rawset(LASTLINEDEFINED, MINUSONE); } diff --git a/src/test/resources/spec/_prelude.lua b/src/test/resources/spec/_prelude.lua index eee99311..35ea8acf 100644 --- a/src/test/resources/spec/_prelude.lua +++ b/src/test/resources/spec/_prelude.lua @@ -3,6 +3,17 @@ -- busted. +local function key_compare(a, b) + local ta, tb = type(a), type(b) + + if ta == "string" then return tb ~= "string" or a < b + elseif tb == "string" then return false + end + + if ta == "number" then return tb ~= "number" or a < b end + return false +end + local function serialise(value, seen, indent) local ty = type(value) if ty == "string" then return (("%q"):format(value):gsub("\\n", "n")) @@ -26,9 +37,13 @@ local function serialise(value, seen, indent) if item:find("\n") then contents_len = math.huge end end + table.sort(keys, key_compare) + local contents_len = 0 for i = 1, keysn - 1 do - local k, v, item = keys[i], value[k] + local k = keys[i] + local v = value[k] + local item if type(k) == "string" and k:match("^[%a_][%w_]*$") then item = ("%s = %s"):format(k, serialise(v, seen, indent + 1)) else diff --git a/src/test/resources/spec/debug_spec.lua b/src/test/resources/spec/debug_spec.lua index 4106b96b..9af2b27f 100644 --- a/src/test/resources/spec/debug_spec.lua +++ b/src/test/resources/spec/debug_spec.lua @@ -67,4 +67,23 @@ describe("The debug library", function() expect(counts.line):eq(59) end) end) + + describe("debug.getinfo", function() + it("a native function :lua>=5.3", function() + expect(debug.getinfo(print)):matches { + nups = 0, + currentline = -1, + func = print, + istailcall = false, + isvararg = true, + lastlinedefined = -1, + linedefined = -1, + namewhat = "", + nparams = 0, + short_src = "[C]", + source = "=[C]", + what = "C", + } + end) + end) end)