Skip to content

Path.Context.Wrap.Static causes global env inside Path.Wrap of a nested function call to be missing some game globals #20

Description

@adi1998

This is only observed when ModUtil is used in Hades 2 (Hell2Modding). Suggested replacement implementations by @AndreLouisIssa that seem to work for a very simple repro.

ModUtil.Context.Call = ModUtil.Context(
    function( info )
        info.env = setmetatable( { }, { __index = info.penv } )
        return table.unpack( info.args )
    end,
    function( info )
        local thread = coroutine.running( )
        local penv = threadEnvironments[ thread ]
        threadEnvironments[ thread ] = setmetatable( info.env, { __index = info.penv, __newindex = info.penv } )
        local ret = table.pack( info.arg( table.unpack( info.args ) ) )
        threadEnvironments[ thread ] = penv
        return table.unpack( ret )
    end
)

ModUtil.Context.Wrap.Static = ModUtil.Context(
    function( info )
        info.env = setmetatable( { }, { __index = info.penv } )
    end,
    function( info )
        return ModUtil.Wrap( info.arg, function( base, ... ) 
            local thread = coroutine.running( )
            local penv = threadEnvironments[ thread ]
            threadEnvironments[ thread ] = setmetatable( info.env, { __index = info.penv, __newindex = info.penv } )
            local ret = table.pack( base( ... ) )
            threadEnvironments[ thread ] = penv
            return table.unpack( ret )
        end, info.args[1] )
    end
)

some more context in the form a discord thread :) https://discord.com/channels/667753182608359424/1485464228180529182/1531648075482005505

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions