3rd attempt at fixing upvalues

This commit is contained in:
Cooldude2606
2018-10-26 14:35:05 +01:00
parent 9f38f6a0f1
commit f14c50852c
7 changed files with 14 additions and 16 deletions

View File

@@ -33,8 +33,8 @@ Event.register(-1,function(event)
if tree and tree.valid then tree.destroy() end
end
end):on_event(defines.events.on_marked_for_deconstruction,function(self,event)
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
local chache = self.data.chache[event.player_index]
if not chache then
local player = Game.get_player(event)

View File

@@ -62,8 +62,8 @@ script.on_init(function(event)
player_return({'ExpGamingBot-autoMessage.message',message},nil,player)
end
end):on_event('error',function(self,err)
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if Sync then Sync.emit_embeded{
title='Auto Message Error',
color=Color.to_hex(defines.textcolor.bg),

View File

@@ -88,8 +88,8 @@ function popup.open(style,data,players)
Server.new_thread{
data={players=players,popup=_popup,data=data}
}:on_event('tick',function(thread)
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if #thread.data.players == 0 then thread:close() return end
local player = table.remove(thread.data.players,1)
if thread.data.popup.left then thread.data.popup.left:close(player) end

View File

@@ -28,8 +28,8 @@ return function(event)
-- posible error handling if needed
error(err)
end):on_event(defines.events.on_player_respawned,function(self,event)
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if self.data.players[event.player_index] then
local remove = {}
local player = Game.get_player(event)

View File

@@ -280,7 +280,6 @@ function Server._thread:create(obj)
obj._env._env = true
obj._env._ENV = nil -- provents infinte recusion
-- removes any modules from the _env to save space in global (less time to serizle)
obj._env.setmetatable = setmetatable
obj._env._modules = {}
for name,value in pairs(obj._env) do if is_type(value,'table') and value._module_name and loaded_modules[value._module_name] == value then obj._env._modules[name] = value._module_name obj._env[name] = nil end end
setmetatable(obj._env,_env_metatable)

View File

@@ -48,11 +48,11 @@ function ExpLib.get_upvalues(level)
local func = level and ExpLib.is_type(level,'function') and level or nil
local level = level and ExpLib.is_type(level,'number') and level+1 or 2
func = func or debug.getinfo(level).func
local upvalues = setmetatable({},{__index=_G})
local upvalues = setmetatable({_order={}},{__index=_G})
local i = 1
while true do
local name, value = debug.getupvalue(func,i)
if not name then break else upvalues[name] = value end
if not name then break else upvalues[name] = value; table.insert(upvalues._order,name) end
i=i+1
end
return upvalues

View File

@@ -6,8 +6,8 @@ script.on_init(function(event)
Server.new_thread{
name='afk-kick',
}:on_event('tick',function(self)
-- the _env should be auto loaded but it does not for some reason
local _ENV = self._env.setmetatable({self=self,event=event},{__index=self._env})
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if (game.tick%3600) ~= 0 then return end
for _,player in pairs(game.connected_players) do
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
@@ -16,9 +16,8 @@ script.on_init(function(event)
end
end
end):on_event('error',function(self,err)
-- the _env should be auto loaded but it does not for some reason
local _ENV = _ENV or setmetatable({},{__index=_G})
_ENV.Sync = self._env.Sync
-- the _env should be auto loaded but it does not for some reasonm this is an attempt to repair the upvalues
for index,name in pairs(self._env._order) do self._env.debug.setupvalue(1,index,self._env[name]) end
if Sync then
Sync.emit_embeded{
title='Auto Kick Error',