forked from Hyperion/HyperionOS
Potential windows case insensitive filesystem issue fix
This commit is contained in:
57
Src/Hyperion-kernel/lib/modules/hyperion/30_userspace.kmod
Normal file
57
Src/Hyperion-kernel/lib/modules/hyperion/30_userspace.kmod
Normal file
@@ -0,0 +1,57 @@
|
||||
-- :Minify:--
|
||||
local args = {...}
|
||||
local kernel = args[1]
|
||||
kernel._G = _G
|
||||
|
||||
|
||||
local function readonly(tbl)
|
||||
return setmetatable({}, {
|
||||
__index = function(_, key)
|
||||
local value = tbl[key]
|
||||
if type(value) == "table" then return readonly(value) end
|
||||
return value
|
||||
end,
|
||||
|
||||
__newindex = function(t, k, v)
|
||||
if kernel.config.allowGlobalOverwrites or
|
||||
kernel.allowGlobalOverwrites then
|
||||
rawset(tbl, k, v)
|
||||
return
|
||||
end
|
||||
error("Attempt to modify global variable '" .. k .. "'", 2)
|
||||
end,
|
||||
|
||||
__pairs = function(self)
|
||||
local function iter(_, key)
|
||||
local nextKey, value = next(tbl, key)
|
||||
if type(value) == "table" then
|
||||
value = readonly(value)
|
||||
end
|
||||
return nextKey, value
|
||||
end
|
||||
return iter, self, nil
|
||||
end,
|
||||
|
||||
__ipairs = function()
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
local value = tbl[i]
|
||||
if value == nil then return end
|
||||
if type(value) == "table" then
|
||||
value = readonly(value)
|
||||
end
|
||||
return i, value
|
||||
end
|
||||
end,
|
||||
|
||||
__len = function() return #tbl end,
|
||||
|
||||
__metatable = false
|
||||
})
|
||||
end
|
||||
local origLoad = load
|
||||
|
||||
kernel._U = readonly(kernel._G)
|
||||
kernel._U._G = kernel._U
|
||||
kernel._U.load = function(a,b,c,d) return origLoad(a,b,c,d or kernel._U) end
|
||||
Reference in New Issue
Block a user