mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 05:27:24 +00:00
make unions with type aliases more usable (#5019)
Some generic C++ and Rust code is not generated when unions use type aliases because of potential ambiguity. Actually check for this ambiguity and only disable offending code only if it is found.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
4c3b6c247d
commit
91fe9ba93f
@@ -477,7 +477,37 @@ function Monster_mt:VectorOfNonOwningReferencesLength()
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster.Start(builder) builder:StartObject(43) end
|
||||
function Monster_mt:AnyUniqueType()
|
||||
local o = self.view:Offset(90)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:AnyUnique()
|
||||
local o = self.view:Offset(92)
|
||||
if o ~= 0 then
|
||||
local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
|
||||
self.view:Union(obj, o)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:AnyAmbiguousType()
|
||||
local o = self.view:Offset(94)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:AnyAmbiguous()
|
||||
local o = self.view:Offset(96)
|
||||
if o ~= 0 then
|
||||
local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
|
||||
self.view:Union(obj, o)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster.Start(builder) builder:StartObject(47) end
|
||||
function Monster.AddPos(builder, pos) builder:PrependStructSlot(0, pos, 0) end
|
||||
function Monster.AddMana(builder, mana) builder:PrependInt16Slot(1, mana, 150) end
|
||||
function Monster.AddHp(builder, hp) builder:PrependInt16Slot(2, hp, 100) end
|
||||
@@ -537,6 +567,10 @@ function Monster.StartVectorOfCoOwningReferencesVector(builder, numElems) return
|
||||
function Monster.AddNonOwningReference(builder, nonOwningReference) builder:PrependUint64Slot(41, nonOwningReference, 0) end
|
||||
function Monster.AddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences) builder:PrependUOffsetTRelativeSlot(42, vectorOfNonOwningReferences, 0) end
|
||||
function Monster.StartVectorOfNonOwningReferencesVector(builder, numElems) return builder:StartVector(8, numElems, 8) end
|
||||
function Monster.AddAnyUniqueType(builder, anyUniqueType) builder:PrependUint8Slot(43, anyUniqueType, 0) end
|
||||
function Monster.AddAnyUnique(builder, anyUnique) builder:PrependUOffsetTRelativeSlot(44, anyUnique, 0) end
|
||||
function Monster.AddAnyAmbiguousType(builder, anyAmbiguousType) builder:PrependUint8Slot(45, anyAmbiguousType, 0) end
|
||||
function Monster.AddAnyAmbiguous(builder, anyAmbiguous) builder:PrependUOffsetTRelativeSlot(46, anyAmbiguous, 0) end
|
||||
function Monster.End(builder) return builder:EndObject() end
|
||||
|
||||
return Monster -- return the module
|
||||
Reference in New Issue
Block a user