Giter Site home page Giter Site logo

debug.getinfo(stacklevel, "S").what returns "Lua" instead of "main" when kleloadlua is used to load files. about dontstarveluajit HOT 5 CLOSED

paintdream avatar paintdream commented on May 20, 2024
debug.getinfo(stacklevel, "S").what returns "Lua" instead of "main" when kleloadlua is used to load files.

from dontstarveluajit.

Comments (5)

Zarklord avatar Zarklord commented on May 20, 2024 1

Hmm, it must be that the person who reported the bug must have been running an outdated version of LuaJIT, I'll fix the tailcalls in my next release so you can remove those hacks.

from dontstarveluajit.

paintdream avatar paintdream commented on May 20, 2024 1

Hmm, it must be that the person who reported the bug must have been running an outdated version of LuaJIT, I'll fix the tailcalls in my next release so you can remove those hacks.

Thanks a lot~

The GemCore is powerful. Thanks the contribution to Don't Starve 's world!

from dontstarveluajit.

paintdream avatar paintdream commented on May 20, 2024

The behavior of debug library of LuaJIT varies from original ones. For example, LuaJIT does not count tailcalls on function stack level.

I've bypassed the compatibility problems between LuaJIT & GemCore by replacing tailcalls with normal function call, by matching code text. It's not the best choice but I have no better idea. see: https://github.com/paintdream/DontStarveLuaJIT/blob/master/src/luajit/src/lib_package.c#L476

Have you released a new verison of GemCore and change the code that calls debug.getinfo()? If so, it would be better if you could remove tail calls on debug.getinfo.... THEN I could remove these unly code....

INSTRUCTIONS: Just as described here: https://github.com/paintdream/DontStarveLuaJIT#to-mod-developers%E5%AF%B9%E4%BA%8Emod%E5%BC%80%E5%8F%91%E8%80%85

Replace:

function a(option)
	return debug.getinfo(1, "option")
end

with:

function a(option)
	return debug.getinfo(1, "option"), nil
end

from dontstarveluajit.

Zarklord avatar Zarklord commented on May 20, 2024

Except thats the weird part, the crash occurs when enabling Gem Core, and I'm not doing the debug call, the game is.
take this crash log: https://pastebin.com/rkLRcJzK the game crashes when GemCore sets a function to GetModModConfigData in the global namespace, the stacktrace even shows that the chunk is considered a "Lua" chunk(line 274 of that crash log), when I was testing on my machine(which doesn't have this installed), I could consistently get debug.getinfo to show the chunk as a "main" chunk, this is not my call to debug.getinfo, and therefore I can't fix it.

from dontstarveluajit.

paintdream avatar paintdream commented on May 20, 2024

I've upgraded GemCore to latest and it runs well. Have you applied the latest DontStarveLuaJIT patch?


OK, let me tell you what happened serveral months ago:

In strict.lua, klei calls debug.getinfo to test if you are in "main":

mt.__newindex = function (t, n, v)
  if __STRICT and not mt.__declared[n] then
    local w = debug.getinfo(2, "S").what
    if w ~= "main" and w ~= "C" then
      error("assign to undeclared variable '"..n.."'", 2)
    end
    mt.__declared[n] = true
  end
  rawset(t, n, v)
end

It works fine. But GemCore hooked the debug.getinfo() in fnhider.lua:


local _debug_getinfo = debug.getinfo
function debug.getinfo(...)
    local args = {...}
    local fnidx = (#args == 3 or (#args == 2 and type(args[2]) ~= "string")) and 2 or 1
    local fn = args[fnidx]
    if type(fn) ~= "function" then
        local stack_count, current, traversed = fn + 1, 2, 1
        if fn > 0 then
            --jump over this function replacement.
            fn = fn + 1
        end
        while traversed < stack_count do
            if hiddenfns[(_debug_getinfo(current, "f") or {}).func] then
                fn = fn + 1
            else
                traversed = traversed + 1
            end
            current = current + 1
        end
        args[fnidx] = fn
    else
        args[fnidx] = hiddenfns[fn] or fn
    end
    return _debug_getinfo(unpack(args)) --<<<<<<<<<<<<<<<<< Look at here!
end

You call original debug.getinfo in tail call, which behaviour divers from lua and luajit: Lua count the tail call as a layer of stack while LuaJIT not. So after applying fnhider.lua, the layer is not correct in LuaJIT.

So I fixed this problem by hooking kleiloadlua to replace your code with:

return _debug_getinfo(unpack(args)), nil -- Add nil HERE!

And it works fine now.

So if you can do the same change as I described above, THEN I could remove the hook to kleiloadlua and everything works fine.
So it look weird that it still crash in your computer. Maybe you are not applied the latest patch? I guess.

Here is my case: (Enabling GemCore with Global Pause, as well as DontStarveLuaJIT, and all things are good)

image

image

from dontstarveluajit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.