2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00

handle nil values in lua iterators

This commit is contained in:
Xjph 2021-12-18 13:23:05 -03:30
parent 714537e58a
commit b2d0637146

View File

@ -26,9 +26,13 @@ namespace Observatory.Explorer
#region Iterators #region Iterators
// Empty function for nil iterators
LuaState.DoString("function nil_iterator() end");
//Materials and AtmosphereComposition //Materials and AtmosphereComposition
LuaState.DoString(@" LuaState.DoString(@"
function materials (material_list) function materials (material_list)
if material_list then
local i = 0 local i = 0
local count = material_list.Count local count = material_list.Count
return function () return function ()
@ -37,11 +41,15 @@ namespace Observatory.Explorer
return { name = material_list[i - 1].Name, percent = material_list[i - 1].Percent } return { name = material_list[i - 1].Name, percent = material_list[i - 1].Percent }
end end
end end
else
return nil_iterator
end
end"); end");
//Rings //Rings
LuaState.DoString(@" LuaState.DoString(@"
function rings (ring_list) function rings (ring_list)
if ring_list then
local i = 0 local i = 0
local count = ring_list.Count local count = ring_list.Count
return function () return function ()
@ -51,11 +59,15 @@ namespace Observatory.Explorer
return { name = ring.Name, ringclass = ring.RingClass, massmt = ring.MassMT, innerrad = ring.InnerRad, outerrad = ring.OuterRad } return { name = ring.Name, ringclass = ring.RingClass, massmt = ring.MassMT, innerrad = ring.InnerRad, outerrad = ring.OuterRad }
end end
end end
else
return nil_iterator
end
end"); end");
//Bodies in system //Bodies in system
LuaState.DoString(@" LuaState.DoString(@"
function bodies (system_list) function bodies (system_list)
if system_list then
local i = 0 local i = 0
local count = system_list.Count local count = system_list.Count
return function () return function ()
@ -64,11 +76,15 @@ namespace Observatory.Explorer
return system_list[i - 1] return system_list[i - 1]
end end
end end
else
return nil_iterator
end
end"); end");
//Parent bodies //Parent bodies
LuaState.DoString(@" LuaState.DoString(@"
function allparents (parent_list) function allparents (parent_list)
if parent_list then
local i = 0 local i = 0
local count local count
if parent_list then count = parent_list.Count else count = 0 end if parent_list then count = parent_list.Count else count = 0 end
@ -78,6 +94,9 @@ namespace Observatory.Explorer
return { parenttype = parent_list[i - 1].ParentType, body = parent_list[i - 1].Body, scan = parent_list[i - 1].Scan } return { parenttype = parent_list[i - 1].ParentType, body = parent_list[i - 1].Body, scan = parent_list[i - 1].Scan }
end end
end end
else
return nil_iterator
end
end"); end");
#endregion #endregion