mirror of
https://github.com/fortressforever/fortressforever-scripts.git
synced 2024-11-22 04:31:07 +00:00
Allow GlobalEntityList to be iterated by pairs and ipairs
* See 6309529590
Example usage:
for ent_id, ent in pairs(GlobalEntityList) do
print(ent_id, ent)
end
Note: The order of iteration is always arbitrary
This commit is contained in:
parent
171376e24c
commit
e8c59ff5ec
1 changed files with 41 additions and 0 deletions
|
@ -49,6 +49,47 @@ function baseclass:new (o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
-- set up pairs and ipairs for iterating the global entity list
|
||||||
|
--
|
||||||
|
-- Example usage:
|
||||||
|
--
|
||||||
|
-- for ent_id, ent in pairs(GlobalEntityList) do
|
||||||
|
-- print(ent_id, ent)
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- Note: The order of iteration is always arbitrary
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
local GlobalEntityListIterator = function()
|
||||||
|
local entity = GlobalEntityList:FirstEntity()
|
||||||
|
return function()
|
||||||
|
local cur_ent = entity
|
||||||
|
entity = GlobalEntityList:NextEntity(cur_ent)
|
||||||
|
if cur_ent then
|
||||||
|
return cur_ent:GetId(), cur_ent
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local ipairs_base = ipairs
|
||||||
|
ipairs = function(t)
|
||||||
|
if t == GlobalEntityList then
|
||||||
|
return GlobalEntityListIterator()
|
||||||
|
end
|
||||||
|
return ipairs_base(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pairs_base = pairs
|
||||||
|
pairs = function(t)
|
||||||
|
if t == GlobalEntityList then
|
||||||
|
return GlobalEntityListIterator()
|
||||||
|
end
|
||||||
|
return pairs_base(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- make luabind's class_info function safer
|
-- make luabind's class_info function safer
|
||||||
-- (don't crash if class_info() is called on non-luabind objects)
|
-- (don't crash if class_info() is called on non-luabind objects)
|
||||||
|
|
Loading…
Reference in a new issue