@@ -624,30 +624,32 @@ function GmEditorUi:onInput(keys)
624
624
end
625
625
626
626
function GmEditorUi :getStringValue (trg , field )
627
- local obj = trg .target
627
+ local obj = trg .target
628
+ local is_union = obj ._type ._union
628
629
629
630
local text = tostring (obj [field ])
630
631
pcall (function ()
631
- if obj ._field ~= nil then
632
- local f = obj :_field (field )
633
- if self .helpers then
634
- if df .coord :is_instance (f ) then
635
- text = (' (%d, %d, %d) %s' ):format (f .x , f .y , f .z , text )
636
- elseif df .coord2d :is_instance (f ) then
637
- text = (' (%d, %d) %s' ):format (f .x , f .y , text )
638
- elseif df .language_name :is_instance (f ) then
639
- text = (' %s (%s) %s' ):format (dfhack .TranslateName (f , false ), dfhack .TranslateName (f , true ), text )
640
- end
641
- end
642
- local enum = f ._type
643
- if enum ._kind == " enum-type" then
644
- text = text .. " (" .. tostring (enum [obj [field ]]).. " )"
645
- end
646
- local ref_target = f .ref_target
647
- if ref_target then
648
- text = text .. " (ref-target: " .. getmetatable (ref_target ).. " )"
632
+ if obj ._field == nil then return end
633
+ local f = obj :_field (field )
634
+ if self .helpers and not is_union then
635
+ if df .coord :is_instance (f ) then
636
+ text = (' (%d, %d, %d) %s' ):format (f .x , f .y , f .z , text )
637
+ elseif df .coord2d :is_instance (f ) then
638
+ text = (' (%d, %d) %s' ):format (f .x , f .y , text )
639
+ elseif df .language_name :is_instance (f ) then
640
+ text = (' %s (%s) %s' ):format (dfhack .TranslateName (f , false ), dfhack .TranslateName (f , true ), text )
649
641
end
650
642
end
643
+ local enum = f ._type
644
+ if enum ._kind == " enum-type" then
645
+ text = text .. " (" .. tostring (enum [obj [field ]]).. " )"
646
+ end
647
+ -- this will throw for types that have no ref target; pcall will catch it, but make sure this bit stays
648
+ -- at the end of the pcall function body
649
+ local ref_target = f .ref_target
650
+ if ref_target then
651
+ text = text .. " (ref-target: " .. getmetatable (ref_target ).. " )"
652
+ end
651
653
end )
652
654
return text
653
655
end
0 commit comments