Skip to content

Commit 7807e5c

Browse files
hades II fix + fix table.remove
1 parent 233dcc8 commit 7807e5c

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

ModUtil.Main.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55

66
-- Management
77

8-
SaveIgnores[ "ModUtil" ] = true
8+
local function setSaveIgnore(key, ignore)
9+
if SaveIgnores then
10+
SaveIgnores[key] = ignore
11+
elseif GlobalSaveWhitelist then
12+
GlobalSaveWhitelist[key] = not ignore
13+
end
14+
end
15+
16+
setSaveIgnore( "ModUtil", true )
917

1018
rawset( _ENV, "GLOBALS", ModUtil.Internal._G )
11-
SaveIgnores[ "GLOBALS" ] = true
19+
setSaveIgnore( "GLOBALS", true )
1220

1321
-- Global Interception
1422

@@ -69,7 +77,7 @@ function ModUtil.Mod.Register( first, second, meta )
6977
end
7078
if not parent then
7179
parent = _G
72-
SaveIgnores[ modName ] = true
80+
setSaveIgnore( modName, true )
7381
end
7482
local mod = parent[ modName ] or { }
7583
parent[ modName ] = mod
@@ -175,7 +183,7 @@ end
175183
ModUtil.Mod.Data = setmetatable( { }, {
176184
__call = function( _, mod )
177185
ModData = ModData or { }
178-
SaveIgnores["ModData"] = false
186+
setSaveIgnore( "ModData", false )
179187
local key = ModUtil.Mods.Inverse[ mod ]
180188
local data = ModData[ key ]
181189
if not data then
@@ -275,7 +283,7 @@ end
275283

276284
do
277285
local ups = ModUtil.UpValues( function( )
278-
return _G, funcsToLoad, loadFuncs, isPath, routeKey, callableCandidateTypes,
286+
return _G, funcsToLoad, loadFuncs, isPath, routeKey, callableCandidateTypes, setSaveIgnore,
279287
objectData, passByValueTypes, modDataKey, modDataProxy, modDataPlain, relativeTable
280288
end )
281289
ModUtil.Entangled.Union.Add( ModUtil.Internal, ups )

ModUtil.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ ModUtil = {
1515
IndexArray = { },
1616
Entangled = { },
1717
Metatables = { }
18-
1918
}
2019

2120
-- Extended Global Utilities (assuming lua 5.2)
2221

2322
local error, pcall, xpcall = error, pcall, xpcall
2423

25-
local debug, type, table = debug, type, table
24+
local debug, type, table, unpack = debug, type, table, table.unpack
2625
local function getname( )
27-
return debug.getinfo( 2, "n" ).name
26+
return debug.getinfo( 2, "n" ).name or "?"
2827
end
2928

3029
-- doesn't invoke __index
@@ -33,14 +32,14 @@ local rawnext = rawnext
3332

3433
local function pusherror( f, ... )
3534
local ret = table.pack( pcall( f, ... ) )
36-
if ret[ 1 ] then return table.rawunpack( ret, 2, ret.n ) end
35+
if ret[ 1 ] then return unpack( ret, 2, ret.n ) end
3736
error( ret[ 2 ], 3 )
3837
end
3938

4039
-- invokes __next
4140
function next( t, k )
4241
local m = debug.getmetatable( t )
43-
local f = m and m.__next or rawnext
42+
local f = m and rawget(m,'__next') or rawnext
4443
return pusherror( f, t, k )
4544
end
4645

@@ -85,7 +84,7 @@ local rawinext = rawinext
8584
-- invokes __inext
8685
function inext( t, i )
8786
local m = debug.getmetatable( t )
88-
local f = m and m.__inext or rawinext
87+
local f = m and rawget(m,'__inext') or rawinext
8988
return pusherror( f, t, i )
9089
end
9190

@@ -189,7 +188,7 @@ function table.remove( list, pos )
189188
if pos == nil then
190189
pos = last
191190
end
192-
if pos < 1 or pos > last then
191+
if pos < 0 or pos > last + 1 then
193192
error( "bad argument #2 to '" .. getname( ) .. "' (position out of bounds)", 2 )
194193
end
195194
local value = list[ pos ]
@@ -203,16 +202,16 @@ function table.remove( list, pos )
203202
return value
204203
end
205204

206-
table.rawunpack = table.unpack
205+
table.rawunpack = unpack
207206
-- table.unpack that respects metamethods
208207
do
209-
local function unpack( t, m, i, ... )
208+
local function _unpack( t, m, i, ... )
210209
if i < m then return ... end
211-
return unpack( t, m, i - 1, t[ i ], ... )
210+
return _unpack( t, m, i - 1, t[ i ], ... )
212211
end
213212

214213
function table.unpack( list, i, j )
215-
return unpack( list, i or 1, j or list.n or #list or 1 )
214+
return _unpack( list, i or 1, j or list.n or #list or 1 )
216215
end
217216
end
218217

0 commit comments

Comments
 (0)