Monster

--[[ MyGame.Example.Monster

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local __MyGame_Example_Ability = require('MyGame.Example.Ability')
local __MyGame_Example_Referrable = require('MyGame.Example.Referrable')
local __MyGame_Example_Stat = require('MyGame.Example.Stat')
local __MyGame_Example_Test = require('MyGame.Example.Test')
local __MyGame_Example_Vec3 = require('MyGame.Example.Vec3')
local __MyGame_InParentNamespace = require('MyGame.InParentNamespace')
local flatbuffers = require('flatbuffers')

-- an example documentation comment: "monster object"
local Monster = {}
local mt = {}

function Monster.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function Monster.GetRootAsMonster(buf, offset)
  if type(buf) == "string" then
    buf = flatbuffers.binaryArray.New(buf)
  end

  local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
  local o = Monster.New()
  o:Init(buf, n + offset)
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Pos()
  local o = self.view:Offset(4)
  if o ~= 0 then
    local x = self.view.pos + o
    local obj = __MyGame_Example_Vec3.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:Mana()
  local o = self.view:Offset(6)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int16, self.view.pos + o)
  end
  return 150
end

function mt:Hp()
  local o = self.view:Offset(8)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int16, self.view.pos + o)
  end
  return 100
end

function mt:Name()
  local o = self.view:Offset(10)
  if o ~= 0 then
    return self.view:String(self.view.pos + o)
  end
end

function mt:Inventory(j)
  local o = self.view:Offset(14)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
  end
  return 0
end

function mt:InventoryAsString(start, stop)
  return self.view:VectorAsString(14, start, stop)
end

function mt:InventoryLength()
  local o = self.view:Offset(14)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Color()
  local o = self.view:Offset(16)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 8
end

function mt:TestType()
  local o = self.view:Offset(18)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 0
end

function mt:Test()
  local o = self.view:Offset(20)
  if o ~= 0 then
   local obj = flatbuffers.view.New(flatbuffers.binaryArray.New(0), 0)
    self.view:Union(obj, o)
    return obj
  end
end

function mt:Test4(j)
  local o = self.view:Offset(22)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    local obj = __MyGame_Example_Test.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:Test4Length()
  local o = self.view:Offset(22)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Testarrayofstring(j)
  local o = self.view:Offset(24)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:String(a + ((j-1) * 4))
  end
  return ''
end

function mt:TestarrayofstringLength()
  local o = self.view:Offset(24)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

-- an example documentation comment: this will end up in the generated code
-- multiline too
function mt:Testarrayoftables(j)
  local o = self.view:Offset(26)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    x = self.view:Indirect(x)
    local obj = Monster.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:TestarrayoftablesLength()
  local o = self.view:Offset(26)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Enemy()
  local o = self.view:Offset(28)
  if o ~= 0 then
    local x = self.view:Indirect(self.view.pos + o)
    local obj = Monster.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:Testnestedflatbuffer(j)
  local o = self.view:Offset(30)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
  end
  return 0
end

function mt:TestnestedflatbufferAsString(start, stop)
  return self.view:VectorAsString(30, start, stop)
end

function mt:TestnestedflatbufferLength()
  local o = self.view:Offset(30)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Testempty()
  local o = self.view:Offset(32)
  if o ~= 0 then
    local x = self.view:Indirect(self.view.pos + o)
    local obj = __MyGame_Example_Stat.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:Testbool()
  local o = self.view:Offset(34)
  if o ~= 0 then
    return (self.view:Get(flatbuffers.N.Bool, self.view.pos + o) ~=0)
  end
  return false
end

function mt:Testhashs32Fnv1()
  local o = self.view:Offset(36)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int32, self.view.pos + o)
  end
  return 0
end

function mt:Testhashu32Fnv1()
  local o = self.view:Offset(38)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint32, self.view.pos + o)
  end
  return 0
end

function mt:Testhashs64Fnv1()
  local o = self.view:Offset(40)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int64, self.view.pos + o)
  end
  return 0
end

function mt:Testhashu64Fnv1()
  local o = self.view:Offset(42)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:Testhashs32Fnv1a()
  local o = self.view:Offset(44)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int32, self.view.pos + o)
  end
  return 0
end

function mt:Testhashu32Fnv1a()
  local o = self.view:Offset(46)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint32, self.view.pos + o)
  end
  return 0
end

function mt:Testhashs64Fnv1a()
  local o = self.view:Offset(48)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int64, self.view.pos + o)
  end
  return 0
end

function mt:Testhashu64Fnv1a()
  local o = self.view:Offset(50)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:Testarrayofbools(j)
  local o = self.view:Offset(52)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Bool, a + ((j-1) * 1))
  end
  return 0
end

function mt:TestarrayofboolsAsString(start, stop)
  return self.view:VectorAsString(52, start, stop)
end

function mt:TestarrayofboolsLength()
  local o = self.view:Offset(52)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Testf()
  local o = self.view:Offset(54)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return 3.14159
end

function mt:Testf2()
  local o = self.view:Offset(56)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return 3.0
end

function mt:Testf3()
  local o = self.view:Offset(58)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return 0.0
end

function mt:Testarrayofstring2(j)
  local o = self.view:Offset(60)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:String(a + ((j-1) * 4))
  end
  return ''
end

function mt:Testarrayofstring2Length()
  local o = self.view:Offset(60)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Testarrayofsortedstruct(j)
  local o = self.view:Offset(62)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 8)
    local obj = __MyGame_Example_Ability.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:TestarrayofsortedstructLength()
  local o = self.view:Offset(62)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Flex(j)
  local o = self.view:Offset(64)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
  end
  return 0
end

function mt:FlexAsString(start, stop)
  return self.view:VectorAsString(64, start, stop)
end

function mt:FlexLength()
  local o = self.view:Offset(64)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Test5(j)
  local o = self.view:Offset(66)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    local obj = __MyGame_Example_Test.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:Test5Length()
  local o = self.view:Offset(66)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:VectorOfLongs(j)
  local o = self.view:Offset(68)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Int64, a + ((j-1) * 8))
  end
  return 0
end

function mt:VectorOfLongsLength()
  local o = self.view:Offset(68)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:VectorOfDoubles(j)
  local o = self.view:Offset(70)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Float64, a + ((j-1) * 8))
  end
  return 0
end

function mt:VectorOfDoublesLength()
  local o = self.view:Offset(70)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:ParentNamespaceTest()
  local o = self.view:Offset(72)
  if o ~= 0 then
    local x = self.view:Indirect(self.view.pos + o)
    local obj = __MyGame_InParentNamespace.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:VectorOfReferrables(j)
  local o = self.view:Offset(74)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    x = self.view:Indirect(x)
    local obj = __MyGame_Example_Referrable.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:VectorOfReferrablesLength()
  local o = self.view:Offset(74)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:SingleWeakReference()
  local o = self.view:Offset(76)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:VectorOfWeakReferences(j)
  local o = self.view:Offset(78)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint64, a + ((j-1) * 8))
  end
  return 0
end

function mt:VectorOfWeakReferencesLength()
  local o = self.view:Offset(78)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:VectorOfStrongReferrables(j)
  local o = self.view:Offset(80)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    x = self.view:Indirect(x)
    local obj = __MyGame_Example_Referrable.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:VectorOfStrongReferrablesLength()
  local o = self.view:Offset(80)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:CoOwningReference()
  local o = self.view:Offset(82)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:VectorOfCoOwningReferences(j)
  local o = self.view:Offset(84)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint64, a + ((j-1) * 8))
  end
  return 0
end

function mt:VectorOfCoOwningReferencesLength()
  local o = self.view:Offset(84)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:NonOwningReference()
  local o = self.view:Offset(86)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:VectorOfNonOwningReferences(j)
  local o = self.view:Offset(88)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint64, a + ((j-1) * 8))
  end
  return 0
end

function mt:VectorOfNonOwningReferencesLength()
  local o = self.view:Offset(88)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:AnyUniqueType()
  local o = self.view:Offset(90)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 0
end

function mt:AnyUnique()
  local o = self.view:Offset(92)
  if o ~= 0 then
   local obj = flatbuffers.view.New(flatbuffers.binaryArray.New(0), 0)
    self.view:Union(obj, o)
    return obj
  end
end

function mt:AnyAmbiguousType()
  local o = self.view:Offset(94)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 0
end

function mt:AnyAmbiguous()
  local o = self.view:Offset(96)
  if o ~= 0 then
   local obj = flatbuffers.view.New(flatbuffers.binaryArray.New(0), 0)
    self.view:Union(obj, o)
    return obj
  end
end

function mt:VectorOfEnums(j)
  local o = self.view:Offset(98)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
  end
  return 0
end

function mt:VectorOfEnumsAsString(start, stop)
  return self.view:VectorAsString(98, start, stop)
end

function mt:VectorOfEnumsLength()
  local o = self.view:Offset(98)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:SignedEnum()
  local o = self.view:Offset(100)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int8, self.view.pos + o)
  end
  return -1
end

function mt:Testrequirednestedflatbuffer(j)
  local o = self.view:Offset(102)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
  end
  return 0
end

function mt:TestrequirednestedflatbufferAsString(start, stop)
  return self.view:VectorAsString(102, start, stop)
end

function mt:TestrequirednestedflatbufferLength()
  local o = self.view:Offset(102)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:ScalarKeySortedTables(j)
  local o = self.view:Offset(104)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    x = self.view:Indirect(x)
    local obj = __MyGame_Example_Stat.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:ScalarKeySortedTablesLength()
  local o = self.view:Offset(104)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:NativeInline()
  local o = self.view:Offset(106)
  if o ~= 0 then
    local x = self.view.pos + o
    local obj = __MyGame_Example_Test.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:LongEnumNonEnumDefault()
  local o = self.view:Offset(108)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:LongEnumNormalDefault()
  local o = self.view:Offset(110)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 2
end

function mt:NanDefault()
  local o = self.view:Offset(112)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return nan
end

function mt:InfDefault()
  local o = self.view:Offset(114)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return inf
end

function mt:PositiveInfDefault()
  local o = self.view:Offset(116)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return inf
end

function mt:InfinityDefault()
  local o = self.view:Offset(118)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return inf
end

function mt:PositiveInfinityDefault()
  local o = self.view:Offset(120)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return inf
end

function mt:NegativeInfDefault()
  local o = self.view:Offset(122)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return -inf
end

function mt:NegativeInfinityDefault()
  local o = self.view:Offset(124)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return -inf
end

function mt:DoubleInfDefault()
  local o = self.view:Offset(126)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float64, self.view.pos + o)
  end
  return inf
end

function Monster.Start(builder)
  builder:StartObject(62)
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

function Monster.AddName(builder, name)
  builder:PrependUOffsetTRelativeSlot(3, name, 0)
end

function Monster.AddInventory(builder, inventory)
  builder:PrependUOffsetTRelativeSlot(5, inventory, 0)
end

function Monster.StartInventoryVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddColor(builder, color)
  builder:PrependUint8Slot(6, color, 8)
end

function Monster.AddTestType(builder, testType)
  builder:PrependUint8Slot(7, testType, 0)
end

function Monster.AddTest(builder, test)
  builder:PrependUOffsetTRelativeSlot(8, test, 0)
end

function Monster.AddTest4(builder, test4)
  builder:PrependUOffsetTRelativeSlot(9, test4, 0)
end

function Monster.StartTest4Vector(builder, numElems)
  return builder:StartVector(4, numElems, 2)
end

function Monster.AddTestarrayofstring(builder, testarrayofstring)
  builder:PrependUOffsetTRelativeSlot(10, testarrayofstring, 0)
end

function Monster.StartTestarrayofstringVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddTestarrayoftables(builder, testarrayoftables)
  builder:PrependUOffsetTRelativeSlot(11, testarrayoftables, 0)
end

function Monster.StartTestarrayoftablesVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddEnemy(builder, enemy)
  builder:PrependStructSlot(12, enemy, 0)
end

function Monster.AddTestnestedflatbuffer(builder, testnestedflatbuffer)
  builder:PrependUOffsetTRelativeSlot(13, testnestedflatbuffer, 0)
end

function Monster.StartTestnestedflatbufferVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddTestempty(builder, testempty)
  builder:PrependStructSlot(14, testempty, 0)
end

function Monster.AddTestbool(builder, testbool)
  builder:PrependBoolSlot(15, testbool, false)
end

function Monster.AddTesthashs32Fnv1(builder, testhashs32Fnv1)
  builder:PrependInt32Slot(16, testhashs32Fnv1, 0)
end

function Monster.AddTesthashu32Fnv1(builder, testhashu32Fnv1)
  builder:PrependUint32Slot(17, testhashu32Fnv1, 0)
end

function Monster.AddTesthashs64Fnv1(builder, testhashs64Fnv1)
  builder:PrependInt64Slot(18, testhashs64Fnv1, 0)
end

function Monster.AddTesthashu64Fnv1(builder, testhashu64Fnv1)
  builder:PrependUint64Slot(19, testhashu64Fnv1, 0)
end

function Monster.AddTesthashs32Fnv1a(builder, testhashs32Fnv1a)
  builder:PrependInt32Slot(20, testhashs32Fnv1a, 0)
end

function Monster.AddTesthashu32Fnv1a(builder, testhashu32Fnv1a)
  builder:PrependUint32Slot(21, testhashu32Fnv1a, 0)
end

function Monster.AddTesthashs64Fnv1a(builder, testhashs64Fnv1a)
  builder:PrependInt64Slot(22, testhashs64Fnv1a, 0)
end

function Monster.AddTesthashu64Fnv1a(builder, testhashu64Fnv1a)
  builder:PrependUint64Slot(23, testhashu64Fnv1a, 0)
end

function Monster.AddTestarrayofbools(builder, testarrayofbools)
  builder:PrependUOffsetTRelativeSlot(24, testarrayofbools, 0)
end

function Monster.StartTestarrayofboolsVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddTestf(builder, testf)
  builder:PrependFloat32Slot(25, testf, 3.14159)
end

function Monster.AddTestf2(builder, testf2)
  builder:PrependFloat32Slot(26, testf2, 3.0)
end

function Monster.AddTestf3(builder, testf3)
  builder:PrependFloat32Slot(27, testf3, 0.0)
end

function Monster.AddTestarrayofstring2(builder, testarrayofstring2)
  builder:PrependUOffsetTRelativeSlot(28, testarrayofstring2, 0)
end

function Monster.StartTestarrayofstring2Vector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddTestarrayofsortedstruct(builder, testarrayofsortedstruct)
  builder:PrependUOffsetTRelativeSlot(29, testarrayofsortedstruct, 0)
end

function Monster.StartTestarrayofsortedstructVector(builder, numElems)
  return builder:StartVector(8, numElems, 4)
end

function Monster.AddFlex(builder, flex)
  builder:PrependUOffsetTRelativeSlot(30, flex, 0)
end

function Monster.StartFlexVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddTest5(builder, test5)
  builder:PrependUOffsetTRelativeSlot(31, test5, 0)
end

function Monster.StartTest5Vector(builder, numElems)
  return builder:StartVector(4, numElems, 2)
end

function Monster.AddVectorOfLongs(builder, vectorOfLongs)
  builder:PrependUOffsetTRelativeSlot(32, vectorOfLongs, 0)
end

function Monster.StartVectorOfLongsVector(builder, numElems)
  return builder:StartVector(8, numElems, 8)
end

function Monster.AddVectorOfDoubles(builder, vectorOfDoubles)
  builder:PrependUOffsetTRelativeSlot(33, vectorOfDoubles, 0)
end

function Monster.StartVectorOfDoublesVector(builder, numElems)
  return builder:StartVector(8, numElems, 8)
end

function Monster.AddParentNamespaceTest(builder, parentNamespaceTest)
  builder:PrependStructSlot(34, parentNamespaceTest, 0)
end

function Monster.AddVectorOfReferrables(builder, vectorOfReferrables)
  builder:PrependUOffsetTRelativeSlot(35, vectorOfReferrables, 0)
end

function Monster.StartVectorOfReferrablesVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddSingleWeakReference(builder, singleWeakReference)
  builder:PrependUint64Slot(36, singleWeakReference, 0)
end

function Monster.AddVectorOfWeakReferences(builder, vectorOfWeakReferences)
  builder:PrependUOffsetTRelativeSlot(37, vectorOfWeakReferences, 0)
end

function Monster.StartVectorOfWeakReferencesVector(builder, numElems)
  return builder:StartVector(8, numElems, 8)
end

function Monster.AddVectorOfStrongReferrables(builder, vectorOfStrongReferrables)
  builder:PrependUOffsetTRelativeSlot(38, vectorOfStrongReferrables, 0)
end

function Monster.StartVectorOfStrongReferrablesVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddCoOwningReference(builder, coOwningReference)
  builder:PrependUint64Slot(39, coOwningReference, 0)
end

function Monster.AddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences)
  builder:PrependUOffsetTRelativeSlot(40, vectorOfCoOwningReferences, 0)
end

function Monster.StartVectorOfCoOwningReferencesVector(builder, numElems)
  return builder:StartVector(8, numElems, 8)
end

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.AddVectorOfEnums(builder, vectorOfEnums)
  builder:PrependUOffsetTRelativeSlot(47, vectorOfEnums, 0)
end

function Monster.StartVectorOfEnumsVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddSignedEnum(builder, signedEnum)
  builder:PrependInt8Slot(48, signedEnum, -1)
end

function Monster.AddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer)
  builder:PrependUOffsetTRelativeSlot(49, testrequirednestedflatbuffer, 0)
end

function Monster.StartTestrequirednestedflatbufferVector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function Monster.AddScalarKeySortedTables(builder, scalarKeySortedTables)
  builder:PrependUOffsetTRelativeSlot(50, scalarKeySortedTables, 0)
end

function Monster.StartScalarKeySortedTablesVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Monster.AddNativeInline(builder, nativeInline)
  builder:PrependStructSlot(51, nativeInline, 0)
end

function Monster.AddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault)
  builder:PrependUint64Slot(52, longEnumNonEnumDefault, 0)
end

function Monster.AddLongEnumNormalDefault(builder, longEnumNormalDefault)
  builder:PrependUint64Slot(53, longEnumNormalDefault, 2)
end

function Monster.AddNanDefault(builder, nanDefault)
  builder:PrependFloat32Slot(54, nanDefault, nan)
end

function Monster.AddInfDefault(builder, infDefault)
  builder:PrependFloat32Slot(55, infDefault, inf)
end

function Monster.AddPositiveInfDefault(builder, positiveInfDefault)
  builder:PrependFloat32Slot(56, positiveInfDefault, inf)
end

function Monster.AddInfinityDefault(builder, infinityDefault)
  builder:PrependFloat32Slot(57, infinityDefault, inf)
end

function Monster.AddPositiveInfinityDefault(builder, positiveInfinityDefault)
  builder:PrependFloat32Slot(58, positiveInfinityDefault, inf)
end

function Monster.AddNegativeInfDefault(builder, negativeInfDefault)
  builder:PrependFloat32Slot(59, negativeInfDefault, -inf)
end

function Monster.AddNegativeInfinityDefault(builder, negativeInfinityDefault)
  builder:PrependFloat32Slot(60, negativeInfinityDefault, -inf)
end

function Monster.AddDoubleInfDefault(builder, doubleInfDefault)
  builder:PrependFloat64Slot(61, doubleInfDefault, inf)
end

function Monster.End(builder)
  return builder:EndObject()
end

return Monster


Ability

--[[ MyGame.Example.Ability

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Ability = {}
local mt = {}

function Ability.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Id()
  return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 0)
end

function mt:Distance()
  return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 4)
end

function Ability.CreateAbility(builder, id, distance)
  builder:Prep(4, 8)
  builder:PrependUint32(distance)
  builder:PrependUint32(id)
  return builder:Offset()
end

return Ability


Race

--[[ MyGame.Example.Race

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local Race = {
  None = -1,
  Human = 0,
  Dwarf = 1,
  Elf = 2,
}

return Race


Any

--[[ MyGame.Example.Any

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local Any = {
  NONE = 0,
  Monster = 1,
  TestSimpleTableWithEnum = 2,
  MyGame_Example2_Monster = 3,
}

return Any


Referrable

--[[ MyGame.Example.Referrable

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Referrable = {}
local mt = {}

function Referrable.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Id()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function Referrable.Start(builder)
  builder:StartObject(1)
end

function Referrable.AddId(builder, id)
  builder:PrependUint64Slot(0, id, 0)
end

function Referrable.End(builder)
  return builder:EndObject()
end

return Referrable


--[[ MyGame.Example.Vec3

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Vec3 = {}
local mt = {}

function Vec3.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:X()
  return self.view:Get(flatbuffers.N.Float32, self.view.pos + 0)
end

function mt:Y()
  return self.view:Get(flatbuffers.N.Float32, self.view.pos + 4)
end

function mt:Z()
  return self.view:Get(flatbuffers.N.Float32, self.view.pos + 8)
end

function mt:Test1()
  return self.view:Get(flatbuffers.N.Float64, self.view.pos + 16)
end

function mt:Test2()
  return self.view:Get(flatbuffers.N.Uint8, self.view.pos + 24)
end

function mt:Test3(obj)
  obj:Init(self.view.bytes, self.view.pos + 26)
  return obj
end

function Vec3.CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b)
  builder:Prep(8, 32)
  builder:Pad(2)
  builder:Prep(2, 4)
  builder:Pad(1)
  builder:PrependInt8(test3_b)
  builder:PrependInt16(test3_a)
  builder:Pad(1)
  builder:PrependUint8(test2)
  builder:PrependFloat64(test1)
  builder:Pad(4)
  builder:PrependFloat32(z)
  builder:PrependFloat32(y)
  builder:PrependFloat32(x)
  return builder:Offset()
end

return Vec3


Color

--[[ MyGame.Example.Color

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

-- Composite components of Monster color.
local Color = {
  Red = 1,
  -- \brief color Green
  -- Green is bit_flag with value (1u << 1)
  Green = 2,
  -- \brief color Blue (1u << 3)
  Blue = 8,
}

return Color


StructOfStructsOfStructs

--[[ MyGame.Example.StructOfStructsOfStructs

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local StructOfStructsOfStructs = {}
local mt = {}

function StructOfStructsOfStructs.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:A(obj)
  obj:Init(self.view.bytes, self.view.pos + 0)
  return obj
end

function StructOfStructsOfStructs.CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance)
  builder:Prep(4, 20)
  builder:Prep(4, 20)
  builder:Prep(4, 8)
  builder:PrependUint32(a_c_distance)
  builder:PrependUint32(a_c_id)
  builder:Prep(2, 4)
  builder:Pad(1)
  builder:PrependInt8(a_b_b)
  builder:PrependInt16(a_b_a)
  builder:Prep(4, 8)
  builder:PrependUint32(a_a_distance)
  builder:PrependUint32(a_a_id)
  return builder:Offset()
end

return StructOfStructsOfStructs


AnyUniqueAliases

--[[ MyGame.Example.AnyUniqueAliases

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local AnyUniqueAliases = {
  NONE = 0,
  M = 1,
  TS = 2,
  M2 = 3,
}

return AnyUniqueAliases


AnyAmbiguousAliases

--[[ MyGame.Example.AnyAmbiguousAliases

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local AnyAmbiguousAliases = {
  NONE = 0,
  M1 = 1,
  M2 = 2,
  M3 = 3,
}

return AnyAmbiguousAliases


flatbuffers

local m = {}

m.Builder = require("flatbuffers.builder").New
m.N = require("flatbuffers.numTypes")
m.view = require("flatbuffers.view")
m.binaryArray = require("flatbuffers.binaryarray")

return m


local m = {}
local ok, bit = pcall(require, "bit32")
assert(ok, "The Bit32 library must be installed")
assert(pcall(require, "compat53"), "The Compat 5.3 library must be installed")

m.GetAlignSize = function(k, size)
    return bit.band(bit.bnot(k) + 1,(size - 1))
end

if not table.unpack then
    table.unpack = unpack
end

if not table.pack then
    table.pack = pack
end

m.string_pack = string.pack
m.string_unpack = string.unpack

return m


-- We need to put it into a separate file to avoid syntax error like `unexpected symbol near '~'`
local m = {}

m.GetAlignSize = function(k, size)
    return ((~k) + 1) & (size - 1)
end

m.string_pack = string.pack
m.string_unpack = string.unpack

return m


view

local compat = require("flatbuffers.compat")
local string_unpack = compat.string_unpack

local m = {}
local mt = {}

local mt_name = "flatbuffers.view.mt"

local N = require("flatbuffers.numTypes")
local binaryarray = require("flatbuffers.binaryarray")

local function enforceOffset(off)
    if off < 0 or off > 42949672951 then
        error("Offset is not valid")
    end
end

local function unPackUoffset(bytes, off)
    return string_unpack("<I4", bytes.str, off + 1)
end

local function unPackVoffset(bytes, off)
    return string_unpack("<I2", bytes.str, off + 1)
end

function m.New(buf, pos)
    enforceOffset(pos)
    -- need to convert from a string buffer into
    -- a binary array

    local o = {
        bytes = type(buf) == "string" and binaryarray.New(buf) or buf,
        pos = pos,
    }
    setmetatable(o, {__index = mt, __metatable = mt_name})
    return o
end

function mt:Offset(vtableOffset)
    local vtable = self.vtable
    if not vtable then
        vtable = self.pos - self:Get(N.SOffsetT, self.pos)
        self.vtable = vtable
        self.vtableEnd = self:Get(N.VOffsetT, vtable)
    end
    if vtableOffset < self.vtableEnd then
        return unPackVoffset(self.bytes, vtable + vtableOffset)
    end
    return 0
end

function mt:Indirect(off)
    enforceOffset(off)
    return off + unPackUoffset(self.bytes, off)
end

function mt:String(off)
    enforceOffset(off)
    off = off + unPackUoffset(self.bytes, off)
    local start = off + 4
    local length = unPackUoffset(self.bytes, off)
    return self.bytes:Slice(start, start+length)
end

function mt:VectorLen(off)
    enforceOffset(off)
    off = off + self.pos
    off = off + unPackUoffset(self.bytes, off)
    return unPackUoffset(self.bytes, off)
end

function mt:Vector(off)
    enforceOffset(off)
    off = off + self.pos
    return off + self:Get(N.UOffsetT, off) + 4
end

function mt:VectorAsString(off, start, stop)
    local o = self:Offset(off)
    if o ~= 0 then
        start = start or 1
        stop = stop or self:VectorLen(o)
        local a = self:Vector(o) + start - 1
        return self.bytes:Slice(a, a + stop - start + 1)
    end
    return nil
end

function mt:Union(t2, off)
    assert(getmetatable(t2) == mt_name)
    enforceOffset(off)
    off = off + self.pos
    t2.pos = off + self:Get(N.UOffsetT, off)
    t2.bytes = self.bytes
end

function mt:Get(flags, off)
    enforceOffset(off)
    return flags:Unpack(self.bytes, off)
end

function mt:GetSlot(slot, d, validatorFlags)
    N.VOffsetT:EnforceNumber(slot)
    if validatorFlags then
        validatorFlags:EnforceNumber(d)
    end
    local off = self:Offset(slot)
    if off == 0 then
        return d
    end
    return self:Get(validatorFlags, self.pos + off)
end

function mt:GetVOffsetTSlot(slot, d)
    N.VOffsetT:EnforceNumbers(slot, d)
    local off = self:Offset(slot)
    if off == 0 then
        return d
    end
    return off
end

return m


builder

local N = require("flatbuffers.numTypes")
local ba = require("flatbuffers.binaryarray")
local compat = require("flatbuffers.compat")
local string_unpack = compat.string_unpack

local m = {}

local mt = {}

-- get locals for faster access
local VOffsetT  = N.VOffsetT
local UOffsetT  = N.UOffsetT
local SOffsetT  = N.SOffsetT
local Bool      = N.Bool
local Uint8     = N.Uint8
local Uint16    = N.Uint16
local Uint32    = N.Uint32
local Uint64    = N.Uint64
local Int8      = N.Int8
local Int16     = N.Int16
local Int32     = N.Int32
local Int64     = N.Int64
local Float32   = N.Float32
local Float64   = N.Float64

local MAX_BUFFER_SIZE = 0x80000000 -- 2 GB
local VtableMetadataFields = 2

local getAlignSize = compat.GetAlignSize

local function vtableEqual(a, objectStart, b)
    UOffsetT:EnforceNumber(objectStart)
    if (#a * 2) ~= #b then
        return false
    end

    for i, elem in ipairs(a) do
        local x = string_unpack(VOffsetT.packFmt, b, 1 + (i - 1) * 2)
        if x ~= 0 or elem ~= 0 then
            local y = objectStart - elem
            if x ~= y then
                return false
            end
        end
    end
    return true
end

function m.New(initialSize)
    assert(0 <= initialSize and initialSize < MAX_BUFFER_SIZE)
    local o =
    {
        finished = false,
        bytes = ba.New(initialSize),
        nested = false,
        head = initialSize,
        minalign = 1,
        vtables = {}
    }
    setmetatable(o, {__index = mt})
    return o
end

-- Clears the builder and resets the state. It does not actually clear the backing binary array, it just reuses it as
-- needed. This is a performant way to use the builder for multiple constructions without the overhead of multiple
-- builder allocations.
function mt:Clear()
    self.finished = false
    self.nested = false
    self.minalign = 1
    self.currentVTable = nil
    self.objectEnd = nil
    self.head = self.bytes.size -- place the head at the end of the binary array

    -- clear vtables instead of making a new table
    local vtable = self.vtables
    local vtableCount = #vtable
    for i=1,vtableCount do vtable[i] = nil end
end

function mt:Output(full)
    assert(self.finished, "Builder Not Finished")
    if full then
        return self.bytes:Slice()
    else
        return self.bytes:Slice(self.head)
    end
end

function mt:StartObject(numFields)
    assert(not self.nested)

    local vtable = {}

    for _=1,numFields do
        table.insert(vtable, 0)
    end

    self.currentVTable = vtable
    self.objectEnd = self:Offset()
    self.nested = true
end

function mt:WriteVtable()
    self:PrependSOffsetTRelative(0)
    local objectOffset = self:Offset()

    local exisitingVTable
    local i = #self.vtables
    while i >= 1 do
        if self.vtables[i] == 0 then
            table.remove(self.vtables,i)
        end
        i = i - 1
    end

    i = #self.vtables
    while i >= 1 do

        local vt2Offset = self.vtables[i]
        local vt2Start = self.bytes.size - vt2Offset
        local vt2lenstr = self.bytes:Slice(vt2Start, vt2Start+1)
        local vt2Len = string_unpack(VOffsetT.packFmt, vt2lenstr, 1)

        local metadata = VtableMetadataFields * 2
        local vt2End = vt2Start + vt2Len
        local vt2 = self.bytes:Slice(vt2Start+metadata,vt2End)

        if vtableEqual(self.currentVTable, objectOffset, vt2) then
            exisitingVTable = vt2Offset
            break
        end

        i = i - 1
    end

    if not exisitingVTable then
        i = #self.currentVTable
        while i >= 1 do
            local off = 0
            local a = self.currentVTable[i]
            if a and a ~= 0 then
                off = objectOffset - a
            end
            self:PrependVOffsetT(off)

            i = i - 1
        end

        local objectSize = objectOffset - self.objectEnd
        self:PrependVOffsetT(objectSize)

        local vBytes = #self.currentVTable + VtableMetadataFields
        vBytes = vBytes * 2
        self:PrependVOffsetT(vBytes)

        local objectStart = self.bytes.size - objectOffset
        self.bytes:Set(SOffsetT:Pack(self:Offset() - objectOffset),objectStart)

        table.insert(self.vtables, self:Offset())
    else
        local objectStart = self.bytes.size - objectOffset
        self.head = objectStart
        self.bytes:Set(SOffsetT:Pack(exisitingVTable - objectOffset),self.head)
    end

    self.currentVTable = nil
    return objectOffset
end

function mt:EndObject()
    assert(self.nested)
    self.nested = false
    return self:WriteVtable()
end

local function growByteBuffer(self, desiredSize)
    local s = self.bytes.size
    assert(s < MAX_BUFFER_SIZE, "Flat Buffers cannot grow buffer beyond 2 gigabytes")
    local newsize = s
    repeat
        newsize = math.min(newsize * 2, MAX_BUFFER_SIZE)
        if newsize == 0 then newsize = 1 end
    until newsize > desiredSize

    self.bytes:Grow(newsize)
end

function mt:Head()
    return self.head
end

function mt:Offset()
   return self.bytes.size - self.head
end

function mt:Pad(n)
    if n > 0 then
        -- pads are 8-bit, so skip the bytewidth lookup
        local h = self.head - n  -- UInt8
        self.head = h
        self.bytes:Pad(n, h)
    end
end

function mt:Prep(size, additionalBytes)
    if size > self.minalign then
        self.minalign = size
    end

    local h = self.head

    local k = self.bytes.size - h + additionalBytes
    local alignsize = getAlignSize(k, size)

    local desiredSize = alignsize + size + additionalBytes

    while self.head < desiredSize do
        local oldBufSize = self.bytes.size
        growByteBuffer(self, desiredSize)
        local updatedHead = self.head + self.bytes.size - oldBufSize
        self.head = updatedHead
    end

    self:Pad(alignsize)
end

function mt:PrependSOffsetTRelative(off)
    self:Prep(4, 0)
    assert(off <= self:Offset(), "Offset arithmetic error")
    local off2 = self:Offset() - off + 4
    self:Place(off2, SOffsetT)
end

function mt:PrependUOffsetTRelative(off)
    self:Prep(4, 0)
    local soffset = self:Offset()
    if off <= soffset then
        local off2 = soffset - off + 4
        self:Place(off2, UOffsetT)
    else
        error("Offset arithmetic error")
    end
end

function mt:StartVector(elemSize, numElements, alignment)
    assert(not self.nested)
    self.nested = true
    local elementSize = elemSize * numElements
    self:Prep(4, elementSize) -- Uint32 length
    self:Prep(alignment, elementSize)
    return self:Offset()
end

function mt:EndVector(vectorNumElements)
    assert(self.nested)
    self.nested = false
    self:Place(vectorNumElements, UOffsetT)
    return self:Offset()
end

function mt:CreateString(s)
    assert(not self.nested)
    self.nested = true

    assert(type(s) == "string")

    self:Prep(4, #s + 1)
    self:Place(0, Uint8)

    local l = #s
    self.head = self.head - l

    self.bytes:Set(s, self.head, self.head + l)

    return self:EndVector(l)
end

function mt:CreateByteVector(x)
    assert(not self.nested)
    self.nested = true

    local l = #x
    self:Prep(4, l)

    self.head = self.head - l

    self.bytes:Set(x, self.head, self.head + l)

    return self:EndVector(l)
end

function mt:Slot(slotnum)
    assert(self.nested)
    -- n.b. slot number is 0-based
    self.currentVTable[slotnum + 1] = self:Offset()
end

local function finish(self, rootTable, sizePrefix)
    UOffsetT:EnforceNumber(rootTable)
    self:Prep(self.minalign, sizePrefix and 8 or 4)
    self:PrependUOffsetTRelative(rootTable)
    if sizePrefix then
        local size = self.bytes.size - self.head
        Int32:EnforceNumber(size)
        self:PrependInt32(size)
    end
    self.finished = true
    return self.head
end

function mt:Finish(rootTable)
    return finish(self, rootTable, false)
end

function mt:FinishSizePrefixed(rootTable)
    return finish(self, rootTable, true)
end

function mt:Prepend(flags, off)
    self:Prep(flags.bytewidth, 0)
    self:Place(off, flags)
end

function mt:PrependSlot(flags, o, x, d)
    flags:EnforceNumbers(x,d)
--    flags:EnforceNumber(x)
--    flags:EnforceNumber(d)
    if x ~= d then
        self:Prepend(flags, x)
        self:Slot(o)
    end
end

function mt:PrependBoolSlot(...)    self:PrependSlot(Bool, ...) end
function mt:PrependByteSlot(...)    self:PrependSlot(Uint8, ...) end
function mt:PrependUint8Slot(...)   self:PrependSlot(Uint8, ...) end
function mt:PrependUint16Slot(...)  self:PrependSlot(Uint16, ...) end
function mt:PrependUint32Slot(...)  self:PrependSlot(Uint32, ...) end
function mt:PrependUint64Slot(...)  self:PrependSlot(Uint64, ...) end
function mt:PrependInt8Slot(...)    self:PrependSlot(Int8, ...) end
function mt:PrependInt16Slot(...)   self:PrependSlot(Int16, ...) end
function mt:PrependInt32Slot(...)   self:PrependSlot(Int32, ...) end
function mt:PrependInt64Slot(...)   self:PrependSlot(Int64, ...) end
function mt:PrependFloat32Slot(...) self:PrependSlot(Float32, ...) end
function mt:PrependFloat64Slot(...) self:PrependSlot(Float64, ...) end

function mt:PrependUOffsetTRelativeSlot(o,x,d)
    if x~=d then
        self:PrependUOffsetTRelative(x)
        self:Slot(o)
    end
end

function mt:PrependStructSlot(v,x,d)
    UOffsetT:EnforceNumber(d)
    if x~=d then
        UOffsetT:EnforceNumber(x)
        assert(x == self:Offset(), "Tried to write a Struct at an Offset that is different from the current Offset of the Builder.")
        self:Slot(v)
    end
end

function mt:PrependBool(x)      self:Prepend(Bool, x) end
function mt:PrependByte(x)      self:Prepend(Uint8, x) end
function mt:PrependUint8(x)     self:Prepend(Uint8, x) end
function mt:PrependUint16(x)    self:Prepend(Uint16, x) end
function mt:PrependUint32(x)    self:Prepend(Uint32, x) end
function mt:PrependUint64(x)    self:Prepend(Uint64, x) end
function mt:PrependInt8(x)      self:Prepend(Int8, x) end
function mt:PrependInt16(x)     self:Prepend(Int16, x) end
function mt:PrependInt32(x)     self:Prepend(Int32, x) end
function mt:PrependInt64(x)     self:Prepend(Int64, x) end
function mt:PrependFloat32(x)   self:Prepend(Float32, x) end
function mt:PrependFloat64(x)   self:Prepend(Float64, x) end
function mt:PrependVOffsetT(x)  self:Prepend(VOffsetT, x) end

function mt:Place(x, flags)
    local d = flags:EnforceNumberAndPack(x)
    local h = self.head - flags.bytewidth
    self.head = h
    self.bytes:Set(d, h)
end

return m


numTypes

local m = {}

local ba = require("flatbuffers.binaryarray")

local bpack = ba.Pack
local bunpack = ba.Unpack

local type_mt =  {}

function type_mt:Pack(value)
    return bpack(self.packFmt, value)
end

function type_mt:Unpack(buf, pos)
    return bunpack(self.packFmt, buf, pos)
end

function type_mt:ValidNumber(n)
    if not self.min_value and not self.max_value then return true end
    return self.min_value <= n and n <= self.max_value
end

function type_mt:EnforceNumber(n)
    -- duplicate code since the overhead of function calls
    -- for such a popular method is time consuming
    if not self.min_value and not self.max_value then
        return
    end

    if self.min_value <= n and n <= self.max_value then
        return
    end

    error("Number is not in the valid range")
end

function type_mt:EnforceNumbers(a,b)
   -- duplicate code since the overhead of function calls
    -- for such a popular method is time consuming
    if not self.min_value and not self.max_value then
        return
    end

    if self.min_value <= a and a <= self.max_value and self.min_value <= b and b <= self.max_value then
        return
    end

    error("Number is not in the valid range")
end

function type_mt:EnforceNumberAndPack(n)
    return bpack(self.packFmt, n)
end

function type_mt:ConvertType(n, otherType)
    assert(self.bytewidth == otherType.bytewidth, "Cannot convert between types of different widths")
    if self == otherType then
        return n
    end
    return otherType:Unpack(self:Pack(n))
end

local bool_mt =
{
    bytewidth = 1,
    min_value = false,
    max_value = true,
    lua_type = type(true),
    name = "bool",
    packFmt = "<I1",
    Pack = function(self, value) return value and "1" or "0" end,
    Unpack = function(self, buf, pos) return buf[pos] == "1" end,
    ValidNumber = function(self, n) return true end, -- anything is a valid boolean in Lua
    EnforceNumber = function(self, n) end, -- anything is a valid boolean in Lua
    EnforceNumbers = function(self, a, b) end, -- anything is a valid boolean in Lua
    EnforceNumberAndPack = function(self, n) return self:Pack(n) end,
}

local uint8_mt =
{
    bytewidth = 1,
    min_value = 0,
    max_value = 2^8-1,
    lua_type = type(1),
    name = "uint8",
    packFmt = "<I1"
}

local uint16_mt =
{
    bytewidth = 2,
    min_value = 0,
    max_value = 2^16-1,
    lua_type = type(1),
    name = "uint16",
    packFmt = "<I2"
}

local uint32_mt =
{
    bytewidth = 4,
    min_value = 0,
    max_value = 2^32-1,
    lua_type = type(1),
    name = "uint32",
    packFmt = "<I4"
}

local uint64_mt =
{
    bytewidth = 8,
    min_value = 0,
    max_value = 2^64-1,
    lua_type = type(1),
    name = "uint64",
    packFmt = "<I8"
}

local int8_mt =
{
    bytewidth = 1,
    min_value = -2^7,
    max_value = 2^7-1,
    lua_type = type(1),
    name = "int8",
    packFmt = "<i1"
}

local int16_mt =
{
    bytewidth = 2,
    min_value = -2^15,
    max_value = 2^15-1,
    lua_type = type(1),
    name = "int16",
    packFmt = "<i2"
}

local int32_mt =
{
    bytewidth = 4,
    min_value = -2^31,
    max_value = 2^31-1,
    lua_type = type(1),
    name = "int32",
    packFmt = "<i4"
}

local int64_mt =
{
    bytewidth = 8,
    min_value = -2^63,
    max_value = 2^63-1,
    lua_type = type(1),
    name = "int64",
    packFmt = "<i8"
}

local float32_mt =
{
    bytewidth = 4,
    min_value = nil,
    max_value = nil,
    lua_type = type(1.0),
    name = "float32",
    packFmt = "<f"
}

local float64_mt =
{
    bytewidth = 8,
    min_value = nil,
    max_value = nil,
    lua_type = type(1.0),
    name = "float64",
    packFmt = "<d"
}

-- register the base class
setmetatable(bool_mt, {__index = type_mt})
setmetatable(uint8_mt, {__index = type_mt})
setmetatable(uint16_mt, {__index = type_mt})
setmetatable(uint32_mt, {__index = type_mt})
setmetatable(uint64_mt, {__index = type_mt})
setmetatable(int8_mt, {__index = type_mt})
setmetatable(int16_mt, {__index = type_mt})
setmetatable(int32_mt, {__index = type_mt})
setmetatable(int64_mt, {__index = type_mt})
setmetatable(float32_mt, {__index = type_mt})
setmetatable(float64_mt, {__index = type_mt})

m.Uint8     = uint8_mt
m.Uint16    = uint16_mt
m.Uint32    = uint32_mt
m.Uint64    = uint64_mt
m.Int8      = int8_mt
m.Int16     = int16_mt
m.Int32     = int32_mt
m.Int64     = int64_mt
m.Float32   = float32_mt
m.Float64   = float64_mt

m.UOffsetT  = uint32_mt
m.VOffsetT  = uint16_mt
m.SOffsetT  = int32_mt

local GenerateTypes = function(listOfTypes)
    for _,t in pairs(listOfTypes) do
        t.Pack = function(self, value) return bpack(self.packFmt, value) end
        t.Unpack = function(self, buf, pos) return bunpack(self.packFmt, buf, pos) end
    end
end

GenerateTypes(m)

-- explicitly execute after GenerateTypes call, as we don't want to define a Pack/Unpack function for it.
m.Bool      = bool_mt
return m


binaryarray

local compat = require("flatbuffers.compat")
-- locals for slightly faster access
local string_pack = compat.string_pack
local string_unpack = compat.string_unpack

local m = {} -- the module table

local mt = {} -- the module metatable

-- given a binary array, set a metamethod to return its length
-- (e.g., #binaryArray, calls this)
function mt:__len()
    return self.size
end

-- Create a new binary array of an initial size
function m.New(sizeOrString)
    -- the array storage itself
    local o = {}

    if type(sizeOrString) == "string" then
        o.str = sizeOrString
        o.size = #sizeOrString
    elseif type(sizeOrString) == "number" then
        o.data = {}
        o.size = sizeOrString
    else
        error("Expect a integer size value or string to construct a binary array")
    end
    -- set the inheritance
    setmetatable(o, {__index = mt, __len = mt.__len})
    return o
end

-- Get a slice of the binary array from start to end position
function mt:Slice(startPos, endPos)
    startPos = startPos or 0
    endPos = endPos or self.size
    local d = self.data
    if d then
        -- if the self.data is defined, we are building the buffer
        -- in a Lua table

        -- new table to store the slice components
        local b = {}

        -- starting with the startPos, put all
        -- values into the new table to be concat later
        -- updated the startPos based on the size of the
        -- value
        while startPos < endPos do
            local v = d[startPos]
            if not v or v == "" then
                v = '/0'
            end
            table.insert(b, v)
            startPos = startPos + #v
        end

        -- combine the table of strings into one string
        -- this is faster than doing a bunch of concats by themselves
        return table.concat(b)
    else
        -- n.b start/endPos are 0-based incoming, so need to convert
        --     correctly. in python a slice includes start -> end - 1
        return self.str:sub(startPos+1, endPos)
    end
end

-- Grow the binary array to a new size, placing the exisiting data
-- at then end of the new array
function mt:Grow(newsize)
    -- the new table to store the data
    local newT = {}

    -- the offset to be applied to existing entries
    local offset = newsize - self.size

    -- loop over all the current entries and
    -- add them to the new table at the correct
    -- offset location
    local d = self.data
    for i,data in pairs(d) do
        newT[i + offset] = data
    end

    -- update this storage with the new table and size
    self.data = newT
    self.size = newsize
end

-- memorization for padding strings
local pads = {}

-- pad the binary with n \0 bytes at the starting position
function mt:Pad(n, startPos)
    -- use memorization to avoid creating a bunch of strings
    -- all the time
    local s = pads[n]
    if not s then
        s = string.rep('\0', n)
        pads[n] = s
    end

    -- store the padding string at the start position in the
    -- Lua table
    self.data[startPos] = s
end

-- Sets the binary array value at the specified position
function mt:Set(value, position)
    self.data[position] = value
end

-- Pack the data into a binary representation
function m.Pack(fmt, ...)
    return string_pack(fmt, ...)
end

-- Unpack the data from a binary representation in
-- a Lua value
function m.Unpack(fmt, s, pos)
    return string_unpack(fmt, s.str, pos + 1)
end

-- Return the binary array module
return m


compat

local compats = {
    ["Lua 5.1"] = function()
        -- Check if Lua JIT is installed first
        local ok = pcall(require, "jit")
        if not ok then
            return require("flatbuffers.compat_5_1")
        else
            return require("flatbuffers.compat_luajit")
        end
    end,
    ["Lua 5.2"] = function() return require("flatbuffers.compat_5_1") end,
    ["Lua 5.3"] = function() return require("flatbuffers.compat_5_3") end,
    ["Lua 5.4"] = function() return require("flatbuffers.compat_5_3") end,
}
return assert(compats[_VERSION], "Unsupported Lua Version: ".._VERSION)()


local bit = require("bit")
local ffi = require("ffi")
local band = bit.band
local bnot = bit.bnot

local m = {}
local Uint8Bound = 256 -- bound is the max uintN + 1
local Uint16Bound = 65536
local Uint32Bound = 4294967296

if not table.unpack then
    table.unpack = unpack
end

if not table.pack then
    table.pack = pack
end

m.GetAlignSize = function(k, size)
    return band((bnot(k) + 1), (size - 1))
end

local function pack_I1(n)
    return string.char(n)
end
local function pack_i1(n)
    if n < 0 then
        n = Uint8Bound + n
    end
    return pack_I1(n)
end

local function unpack_I1(n, pos)
    return string.byte(n, pos)
end
local function unpack_i1(n, pos)
    local res = unpack_I1(n, pos)
    if res >= Uint8Bound / 2 then
        return res - Uint8Bound
    end
    return res
end

local b2 = ffi.new("unsigned char[2]")
local function pack_I2(n)
    for i = 0, 1 do
        b2[i] = bit.band(n, 255)
        n = bit.rshift(n, 8)
    end
    return ffi.string(b2, 2)
end
local function pack_i2(n)
    if n < 0 then
        n = Uint16Bound + n
    end
    return pack_I2(n)
end

local function unpack_I2(n, pos)
    local a, b = string.byte(n, pos, pos + 1)
    return b * Uint8Bound + a
end
local function unpack_i2(n, pos)
    local res = unpack_I2(n, pos)
    if res >= Uint16Bound / 2 then
        return res - Uint16Bound
    end
    return res
end

local b4 = ffi.new("unsigned char[4]")
local function pack_I4(n)
    for i = 0, 3 do
        b4[i] = bit.band(n, 255)
        n = bit.rshift(n, 8)
    end
    return ffi.string(b4, 4)
end
local function pack_i4(n)
    if n < 0 then
        n = Uint32Bound + n
    end
    return pack_I4(n)
end

local function unpack_I4(n, pos)
    local a, b, c, d = string.byte(n, pos, pos + 3)
    return Uint8Bound * (Uint8Bound * ((Uint8Bound * d) + c) + b) + a
end
local function unpack_i4(n, pos)
    local res = unpack_I4(n, pos)
    if res >= Uint32Bound / 2 then
        return res - Uint32Bound
    end
    return res
end

local b8 = ffi.new("unsigned char[8]")
local function pack_I8(n)
    n = ffi.cast("unsigned long long", n)
    local hi = math.floor(tonumber(n / Uint32Bound))
    local li = n % Uint32Bound
    for i = 0, 3 do
        b8[i] = bit.band(li, 255)
        li = bit.rshift(li, 8)
    end
    for i = 4, 7 do
        b8[i] = bit.band(hi, 255)
        hi = bit.rshift(hi, 8)
    end
    return ffi.string(b8, 8)
end
local function pack_i8(n)
    n = ffi.cast("signed long long", n)
    return pack_I8(n)
end

local function unpack_I8(n, pos)
    local a, b, c, d = string.byte(n, pos, pos + 3)
    local li = Uint8Bound * (Uint8Bound * ((Uint8Bound * d) + c) + b) + a
    local a, b, c, d = string.byte(n, pos + 4, pos + 7)
    local hi = Uint8Bound * (Uint8Bound * ((Uint8Bound * d) + c) + b) + a
    return ffi.cast("unsigned long long", hi) * Uint32Bound + li
end
local function unpack_i8(n, pos)
    local res = unpack_I8(n, pos)
    return ffi.cast("signed long long", res)
end

local bf = ffi.new("float[1]")
local function pack_f(n)
    bf[0] = n
    return ffi.string(bf, 4)
end

local function unpack_f(n, pos)
    ffi.copy(bf, ffi.cast("char *", n) + pos - 1, 4)
    return tonumber(bf[0])
end

local bd = ffi.new("double[1]")
local function pack_d(n)
    bd[0] = n
    return ffi.string(bd, 8)
end

local function unpack_d(n, pos)
    ffi.copy(bd, ffi.cast("char *", n) + pos - 1, 8)
    return tonumber(bd[0])
end

m.string_pack = function(fmt, i, ...)
    if fmt == "<I1" then
        return pack_I1(i)
    elseif fmt == "<I2" then
        return pack_I2(i)
    elseif fmt == "<I4" then
        return pack_I4(i)
    elseif fmt == "<I8" then
        return pack_I8(i)
    elseif fmt == "<i1" then
        return pack_i1(i)
    elseif fmt == "<i2" then
        return pack_i2(i)
    elseif fmt == "<i4" then
        return pack_i4(i)
    elseif fmt == "<i8" then
        return pack_i8(i)
    elseif fmt == "<f" then
        return pack_f(i)
    elseif fmt == "<d" then
        return pack_d(i)
    else
        error(string.format("FIXME: support fmt %s", fmt))
    end
end

m.string_unpack = function(fmt, s, pos)
    if not pos then
        pos = 1
    end

    if fmt == "<I1" then
        return unpack_I1(s, pos)
    elseif fmt == "<I2" then
        return unpack_I2(s, pos)
    elseif fmt == "<I4" then
        return unpack_I4(s, pos)
    elseif fmt == "<I8" then
        return unpack_I8(s, pos)
    elseif fmt == "<i1" then
        return unpack_i1(s, pos)
    elseif fmt == "<i2" then
        return unpack_i2(s, pos)
    elseif fmt == "<i4" then
        return unpack_i4(s, pos)
    elseif fmt == "<i8" then
        return unpack_i8(s, pos)
    elseif fmt == "<f" then
        return unpack_f(s, pos)
    elseif fmt == "<d" then
        return unpack_d(s, pos)
    else
        error(string.format("FIXME: support fmt %s", fmt))
    end
end

return m


Galaxy

--[[ Galaxy

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //basic.fbs
  Rooting type : Universe (//basic.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Galaxy = {}
local mt = {}

function Galaxy.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:NumStars()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int64, self.view.pos + o)
  end
  return 0
end

function Galaxy.Start(builder)
  builder:StartObject(1)
end

function Galaxy.AddNumStars(builder, numStars)
  builder:PrependInt64Slot(0, numStars, 0)
end

function Galaxy.End(builder)
  return builder:EndObject()
end

return Galaxy


Universe

--[[ Universe

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //basic.fbs
  Rooting type : Universe (//basic.fbs)

--]]

local __Galaxy = require('Galaxy')
local flatbuffers = require('flatbuffers')

local Universe = {}
local mt = {}

function Universe.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function Universe.GetRootAsUniverse(buf, offset)
  if type(buf) == "string" then
    buf = flatbuffers.binaryArray.New(buf)
  end

  local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
  local o = Universe.New()
  o:Init(buf, n + offset)
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Age()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float64, self.view.pos + o)
  end
  return 0.0
end

function mt:Galaxies(j)
  local o = self.view:Offset(6)
  if o ~= 0 then
    local x = self.view:Vector(o)
    x = x + ((j-1) * 4)
    x = self.view:Indirect(x)
    local obj = __Galaxy.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function mt:GalaxiesLength()
  local o = self.view:Offset(6)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function Universe.Start(builder)
  builder:StartObject(2)
end

function Universe.AddAge(builder, age)
  builder:PrependFloat64Slot(0, age, 0.0)
end

function Universe.AddGalaxies(builder, galaxies)
  builder:PrependUOffsetTRelativeSlot(1, galaxies, 0)
end

function Universe.StartGalaxiesVector(builder, numElems)
  return builder:StartVector(4, numElems, 4)
end

function Universe.End(builder)
  return builder:EndObject()
end

return Universe


TableA

--[[ TableA

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //include_test/include_test1.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local __MyGame_OtherNameSpace_TableB = require('MyGame.OtherNameSpace.TableB')
local flatbuffers = require('flatbuffers')

local TableA = {}
local mt = {}

function TableA.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:B()
  local o = self.view:Offset(4)
  if o ~= 0 then
    local x = self.view:Indirect(self.view.pos + o)
    local obj = __MyGame_OtherNameSpace_TableB.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function TableA.Start(builder)
  builder:StartObject(1)
end

function TableA.AddB(builder, b)
  builder:PrependStructSlot(0, b, 0)
end

function TableA.End(builder)
  return builder:EndObject()
end

return TableA


luatest

package.path = string.format("../lua/?.lua;./?.lua;%s",package.path)
local compat = require("flatbuffers.compat")

local performBenchmarkTests = false

if #arg > 1 then
    print("usage: lua luatests [benchmark]");
    return
elseif #arg > 0 then
    if(arg[1] == "benchmark") then
        performBenchmarkTests = true
    end
end

local function checkReadBuffer(buf, offset, sizePrefix)
    offset = offset or 0

    if type(buf) == "string" then
        buf = flatbuffers.binaryArray.New(buf)
    end

    if sizePrefix then
        local size = flatbuffers.N.Int32:Unpack(buf, offset)
        assert(size == buf.size - offset - 4)
        offset = offset + flatbuffers.N.Int32.bytewidth
    end

    local mon = monster.GetRootAsMonster(buf, offset)
    assert(mon:Hp() == 80, "Monster Hp is not 80")
    assert(mon:Mana() == 150, "Monster Mana is not 150")
    assert(mon:Name() == "MyMonster", "Monster Name is not MyMonster")
    assert(mon:Testbool() == true)

    local vec = assert(mon:Pos(), "Monster Position is nil")
    assert(vec:X() == 1.0)
    assert(vec:Y() == 2.0)
    assert(vec:Z() == 3.0)
    assert(vec:Test1() == 3.0)
    assert(vec:Test2() == 2)

    local t = require("MyGame.Example.Test").New()
    t = assert(vec:Test3(t))

    assert(t:A() == 5)
    assert(t:B() == 6)

    local ut = require("MyGame.Example.Any")
    assert(mon:TestType() == ut.Monster)

    local table2 = mon:Test()
    assert(getmetatable(table2) == "flatbuffers.view.mt")

    local mon2 = monster.New()
    mon2:Init(table2.bytes, table2.pos)

    assert(mon2:Name() == "Fred")

    assert(mon:InventoryLength() == 5)
    local invsum = 0
    for i=1,mon:InventoryLength() do
        local v = mon:Inventory(i)
        invsum = invsum + v
    end
    assert(invsum == 10)

    for i=1,5 do
        assert(mon:VectorOfLongs(i) == 10^((i-1)*2))
    end

    local dbls = { -1.7976931348623157e+308, 0, 1.7976931348623157e+308}
    for i=1,mon:VectorOfDoublesLength() do
        assert(mon:VectorOfDoubles(i) == dbls[i])
    end

    assert(mon:Test4Length() == 2)

    local test0 = mon:Test4(1)
    local test1 = mon:Test4(2)

    local v0 = test0:A()
    local v1 = test0:B()
    local v2 = test1:A()
    local v3 = test1:B()

    local sumtest12 = v0 + v1 + v2 + v3
    assert(sumtest12 == 100)

    assert(mon:TestarrayofstringLength() == 2)
    assert(mon:Testarrayofstring(1) == "test1")
    assert(mon:Testarrayofstring(2) == "test2")

    assert(mon:TestarrayoftablesLength() == 0)
    assert(mon:TestnestedflatbufferLength() == 0)
    assert(mon:Testempty() == nil)
end

local function generateMonster(sizePrefix, b)
    if b then b:Clear() end
    b = b or flatbuffers.Builder(0)
    local str = b:CreateString("MyMonster")
    local test1 = b:CreateString("test1")
    local test2 = b:CreateString("test2")
    local fred = b:CreateString("Fred")

    monster.StartInventoryVector(b, 5)
    b:PrependByte(4)
    b:PrependByte(3)
    b:PrependByte(2)
    b:PrependByte(1)
    b:PrependByte(0)
    local inv = b:EndVector(5)

    monster.Start(b)
    monster.AddName(b, fred)
    local mon2 = monster.End(b)

    monster.StartTest4Vector(b, 2)
    test.CreateTest(b, 10, 20)
    test.CreateTest(b, 30, 40)
    local test4 = b:EndVector(2)

    monster.StartTestarrayofstringVector(b, 2)
    b:PrependUOffsetTRelative(test2)
    b:PrependUOffsetTRelative(test1)
    local testArrayOfString = b:EndVector(2)

    monster.StartVectorOfLongsVector(b, 5)
    b:PrependInt64(100000000)
    b:PrependInt64(1000000)
    b:PrependInt64(10000)
    b:PrependInt64(100)
    b:PrependInt64(1)
    local vectorOfLongs = b:EndVector(5)

    monster.StartVectorOfDoublesVector(b, 3)
    b:PrependFloat64(1.7976931348623157e+308)
    b:PrependFloat64(0)
    b:PrependFloat64(-1.7976931348623157e+308)
    local vectorOfDoubles = b:EndVector(3)

    monster.Start(b)
    local pos = vec3.CreateVec3(b, 1.0, 2.0, 3.0, 3.0, 2, 5, 6)
    monster.AddPos(b, pos)

    monster.AddHp(b, 80)
    monster.AddName(b, str)
    monster.AddInventory(b, inv)
    monster.AddTestType(b, 1)
    monster.AddTest(b, mon2)
    monster.AddTest4(b, test4)
    monster.AddTestbool(b, true)
    monster.AddTestbool(b, false)
    monster.AddTestbool(b, null)
    monster.AddTestbool(b,"true")
    monster.AddTestarrayofstring(b, testArrayOfString)
    monster.AddVectorOfLongs(b, vectorOfLongs)
    monster.AddVectorOfDoubles(b, vectorOfDoubles)
    local mon = monster.End(b)

    if sizePrefix then
        b:FinishSizePrefixed(mon)
    else
        b:Finish(mon)
    end
    return b:Output(true), b:Head()
end

local function sizePrefix(sizePrefix)
    local buf,offset = generateMonster(sizePrefix)
    checkReadBuffer(buf, offset, sizePrefix)
end

local function fbbClear()
    -- Generate a builder that will be 'cleared' and reused to create two different objects.
    local fbb = flatbuffers.Builder(0)

    -- First use the builder to read the normal monster data and verify it works
    local buf, offset = generateMonster(false, fbb)
    checkReadBuffer(buf, offset, false)

    -- Then clear the builder to be used again
    fbb:Clear()

    -- Storage for the built monsters
    local monsters = {}
    local lastBuf

    -- Make another builder that will be use identically to the 'cleared' one so outputs can be compared. Build both the
    -- Cleared builder and new builder in the exact same way, so we can compare their results
    for i, builder in ipairs({fbb, flatbuffers.Builder(0)}) do
        local strOffset = builder:CreateString("Hi there")
        monster.Start(builder)
        monster.AddPos(builder, vec3.CreateVec3(builder, 3.0, 2.0, 1.0, 17.0, 3, 100, 123))
        monster.AddName(builder, strOffset)
        monster.AddMana(builder, 123)
        builder:Finish(monster.End(builder))
        local buf = builder:Output(false)
        if not lastBuf then
            lastBuf = buf
        else
            -- the output, sized-buffer should be identical
            assert(lastBuf == buf, "Monster output buffers are not identical")
        end
        monsters[i] = monster.GetRootAsMonster(flatbuffers.binaryArray.New(buf), 0)
    end

    -- Check that all the fields for the generated monsters are as we expect
    for i, monster in ipairs(monsters) do
        assert(monster:Name() == "Hi there", "Monster Name is not 'Hi There' for monster "..i)
        -- HP is default to 100 in the schema, but we change it in generateMonster to 80, so this is a good test to
        -- see if the cleared builder really clears the data.
        assert(monster:Hp() == 100, "HP doesn't equal the default value for monster "..i)
        assert(monster:Mana() == 123, "Monster Mana is not '123' for monster "..i)
        assert(monster:Pos():X() == 3.0, "Monster vec3.X is not '3' for monster "..i)
    end
end

local function testCanonicalData()
    local f = assert(io.open('monsterdata_test.mon', 'rb'))
    local wireData = f:read("*a")
    f:close()
    checkReadBuffer(wireData)
end

local function testCreateEmptyString()
    local b = flatbuffers.Builder(0)
    local str = b:CreateString("")
    monster.Start(b)
    monster.AddName(b, str)
    b:Finish(monster.End(b))
    local s = b:Output()
    local data = flatbuffers.binaryArray.New(s)
    local mon = monster.GetRootAsMonster(data, 0)
    assert(mon:Name() == "")
end

local function benchmarkMakeMonster(count, reuseBuilder)
    local fbb = reuseBuilder and flatbuffers.Builder(0)
    local length = #(generateMonster(false, fbb))

    local s = os.clock()
    for i=1,count do
        generateMonster(false, fbb)
    end
    local e = os.clock()

    local dur = (e - s)
    local rate = count / (dur * 1000)
    local data = (length * count) / (1024 * 1024)
    local dataRate = data / dur

    print(string.format('built %d %d-byte flatbuffers in %.2fsec: %.2f/msec, %.2fMB/sec',
        count, length, dur, rate, dataRate))
end

local function benchmarkReadBuffer(count)
    local f = assert(io.open('monsterdata_test.mon', 'rb'))
    local buf = f:read("*a")
    f:close()

    local s = os.clock()
    for i=1,count do
        checkReadBuffer(buf)
    end
    local e = os.clock()

    local dur = (e - s)
    local rate = count / (dur * 1000)
    local data = (#buf * count) / (1024 * 1024)
    local dataRate = data / dur

    print(string.format('traversed %d %d-byte flatbuffers in %.2fsec: %.2f/msec, %.2fMB/sec',
        count, #buf, dur, rate, dataRate))
end

local function getRootAs_canAcceptString()
    local f = assert(io.open('monsterdata_test.mon', 'rb'))
    local wireData = f:read("*a")
    f:close()
    assert(type(wireData) == "string", "Data is not a string");
    local mon = monster.GetRootAsMonster(wireData, 0)
    assert(mon:Hp() == 80, "Monster Hp is not 80")
end

local function testAccessByteVectorAsString()
    local f = assert(io.open('monsterdata_test.mon', 'rb'))
    local wireData = f:read("*a")
    f:close()
    local mon = monster.GetRootAsMonster(wireData, 0)
    -- the data of byte array Inventory is [0, 1, 2, 3, 4]
    local s = mon:InventoryAsString(1, 3)
    assert(#s == 3)
    for i = 1, #s do
        assert(string.byte(s, i) == i - 1)
    end

    local s = mon:InventoryAsString(2, 5)
    assert(#s == 4)
    for i = 1, #s do
        assert(string.byte(s, i) == i)
    end

    local s = mon:InventoryAsString(5, 5)
    assert(#s == 1)
    assert(string.byte(s, 1) == 4)

    local s = mon:InventoryAsString(2)
    assert(#s == 4)
    for i = 1, #s do
        assert(string.byte(s, i) == i)
    end

    local s = mon:InventoryAsString()
    assert(#s == 5)
    for i = 1, #s do
        assert(string.byte(s, i) == i - 1)
    end
end

local tests =
{
    {
        f = sizePrefix,
        d = "Test size prefix",
        args = {{true}, {false}}
    },
    {
        f = fbbClear,
        d = "FlatBufferBuilder Clear",
    },
    {
        f = testCanonicalData,
        d = "Tests Canonical flatbuffer file included in repo"
    },
    {
        f = testCreateEmptyString,
        d = "Avoid infinite loop when creating empty string"
    },
    {
        f = getRootAs_canAcceptString,
        d = "Tests that GetRootAs<type>() generated methods accept strings"
    },
    {
        f = testAccessByteVectorAsString,
        d = "Access byte vector as string"
    },
}

local benchmarks =
{
    {
        f = benchmarkMakeMonster,
        d = "Benchmark making monsters",
        args = {
            {100},
            {1000},
            {10000},
            {10000, true}
        }
    },
    {
        f = benchmarkReadBuffer,
        d = "Benchmark reading monsters",
        args = {
            {100},
            {1000},
            {10000},
            -- uncomment following to run 1 million to compare.
            -- Took ~141 seconds on my machine
            --{1000000},
        }
    },
}

local result, err = xpcall(function()
    flatbuffers = assert(require("flatbuffers"))
    monster = assert(require("MyGame.Example.Monster"))
    test = assert(require("MyGame.Example.Test"))
    vec3 = assert(require("MyGame.Example.Vec3"))

    local function buildArgList(tbl)
        local s = ""
        for _,item in ipairs(tbl) do
            s = s .. tostring(item) .. ","
        end
        return s:sub(1,-2)
    end

    if performBenchmarkTests then
        for _,benchmark in ipairs(benchmarks) do
            table.insert(tests, benchmark)
        end
    end

    local testsPassed, testsFailed = 0,0
    for _,test in ipairs(tests) do
        local allargs = test.args or {{}}
        for _,args in ipairs(allargs) do
            local results, err = xpcall(test.f,debug.traceback, table.unpack(args))
            if results then
                testsPassed = testsPassed + 1
            else
                testsFailed = testsFailed + 1
                print(string.format(" Test [%s](%s) failed: \n\t%s",
                        test.d or "",
                        buildArgList(args),
                        err))
            end
        end
    end

    local totalTests = testsPassed + testsFailed
    print(string.format("# of test passed: %d / %d (%.2f%%)",
        testsPassed,
        totalTests,
        totalTests ~= 0
            and 100 * (testsPassed / totalTests)
            or 0)
        )

    return 0
end, debug.traceback)

if not result then
    print("Unable to run tests due to test framework error: ",err)
end

os.exit(result and 0 or -1)


SecondTableInA

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceA

local flatbuffers = require('flatbuffers')

local SecondTableInA = {} -- the module
local SecondTableInA_mt = {} -- the class metatable

function SecondTableInA.New()
    local o = {}
    setmetatable(o, {__index = SecondTableInA_mt})
    return o
end
function SecondTableInA.GetRootAsSecondTableInA(buf, offset)
    if type(buf) == "string" then
        buf = flatbuffers.binaryArray.New(buf)
    end
    local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
    local o = SecondTableInA.New()
    o:Init(buf, n + offset)
    return o
end
function SecondTableInA_mt:Init(buf, pos)
    self.view = flatbuffers.view.New(buf, pos)
end
function SecondTableInA_mt:ReferToC()
    local o = self.view:Offset(4)
    if o ~= 0 then
        local x = self.view:Indirect(o + self.view.pos)
        local obj = require('NamespaceC.TableInC').New()
        obj:Init(self.view.bytes, x)
        return obj
    end
end
function SecondTableInA.Start(builder) builder:StartObject(1) end
function SecondTableInA.AddReferToC(builder, referToC) builder:PrependUOffsetTRelativeSlot(0, referToC, 0) end
function SecondTableInA.End(builder) return builder:EndObject() end

return SecondTableInA -- return the module


TableInFirstNS

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceA

local flatbuffers = require('flatbuffers')

local TableInFirstNS = {} -- the module
local TableInFirstNS_mt = {} -- the class metatable

function TableInFirstNS.New()
    local o = {}
    setmetatable(o, {__index = TableInFirstNS_mt})
    return o
end
function TableInFirstNS.GetRootAsTableInFirstNS(buf, offset)
    if type(buf) == "string" then
        buf = flatbuffers.binaryArray.New(buf)
    end
    local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
    local o = TableInFirstNS.New()
    o:Init(buf, n + offset)
    return o
end
function TableInFirstNS_mt:Init(buf, pos)
    self.view = flatbuffers.view.New(buf, pos)
end
function TableInFirstNS_mt:FooTable()
    local o = self.view:Offset(4)
    if o ~= 0 then
        local x = self.view:Indirect(o + self.view.pos)
        local obj = require('NamespaceA.NamespaceB.TableInNestedNS').New()
        obj:Init(self.view.bytes, x)
        return obj
    end
end
function TableInFirstNS_mt:FooEnum()
    local o = self.view:Offset(6)
    if o ~= 0 then
        return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
    end
    return 0
end
function TableInFirstNS_mt:FooUnionType()
    local o = self.view:Offset(8)
    if o ~= 0 then
        return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
    end
    return 0
end
function TableInFirstNS_mt:FooUnion()
    local o = self.view:Offset(10)
    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 TableInFirstNS_mt:FooStruct()
    local o = self.view:Offset(12)
    if o ~= 0 then
        local x = o + self.view.pos
        local obj = require('NamespaceA.NamespaceB.StructInNestedNS').New()
        obj:Init(self.view.bytes, x)
        return obj
    end
end
function TableInFirstNS.Start(builder) builder:StartObject(5) end
function TableInFirstNS.AddFooTable(builder, fooTable) builder:PrependUOffsetTRelativeSlot(0, fooTable, 0) end
function TableInFirstNS.AddFooEnum(builder, fooEnum) builder:PrependInt8Slot(1, fooEnum, 0) end
function TableInFirstNS.AddFooUnionType(builder, fooUnionType) builder:PrependUint8Slot(2, fooUnionType, 0) end
function TableInFirstNS.AddFooUnion(builder, fooUnion) builder:PrependUOffsetTRelativeSlot(3, fooUnion, 0) end
function TableInFirstNS.AddFooStruct(builder, fooStruct) builder:PrependStructSlot(4, fooStruct, 0) end
function TableInFirstNS.End(builder) return builder:EndObject() end

return TableInFirstNS -- return the module


UnionInNestedNS

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceB

local UnionInNestedNS = {
    NONE = 0,
    TableInNestedNS = 1,
}

return UnionInNestedNS -- return the module


TableInNestedNS

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceB

local flatbuffers = require('flatbuffers')

local TableInNestedNS = {} -- the module
local TableInNestedNS_mt = {} -- the class metatable

function TableInNestedNS.New()
    local o = {}
    setmetatable(o, {__index = TableInNestedNS_mt})
    return o
end
function TableInNestedNS.GetRootAsTableInNestedNS(buf, offset)
    if type(buf) == "string" then
        buf = flatbuffers.binaryArray.New(buf)
    end
    local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
    local o = TableInNestedNS.New()
    o:Init(buf, n + offset)
    return o
end
function TableInNestedNS_mt:Init(buf, pos)
    self.view = flatbuffers.view.New(buf, pos)
end
function TableInNestedNS_mt:Foo()
    local o = self.view:Offset(4)
    if o ~= 0 then
        return self.view:Get(flatbuffers.N.Int32, o + self.view.pos)
    end
    return 0
end
function TableInNestedNS.Start(builder) builder:StartObject(1) end
function TableInNestedNS.AddFoo(builder, foo) builder:PrependInt32Slot(0, foo, 0) end
function TableInNestedNS.End(builder) return builder:EndObject() end

return TableInNestedNS -- return the module


StructInNestedNS

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceB

local flatbuffers = require('flatbuffers')

local StructInNestedNS = {} -- the module
local StructInNestedNS_mt = {} -- the class metatable

function StructInNestedNS.New()
    local o = {}
    setmetatable(o, {__index = StructInNestedNS_mt})
    return o
end
function StructInNestedNS_mt:Init(buf, pos)
    self.view = flatbuffers.view.New(buf, pos)
end
function StructInNestedNS_mt:A()
    return self.view:Get(flatbuffers.N.Int32, self.view.pos + 0)
end
function StructInNestedNS_mt:B()
    return self.view:Get(flatbuffers.N.Int32, self.view.pos + 4)
end
function StructInNestedNS.CreateStructInNestedNS(builder, a, b)
    builder:Prep(4, 8)
    builder:PrependInt32(b)
    builder:PrependInt32(a)
    return builder:Offset()
end

return StructInNestedNS -- return the module


EnumInNestedNS

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceB

local EnumInNestedNS = {
    A = 0,
    B = 1,
    C = 2,
}

return EnumInNestedNS -- return the module


TableInC

-- automatically generated by the FlatBuffers compiler, do not modify

-- namespace: NamespaceC

local flatbuffers = require('flatbuffers')

local TableInC = {} -- the module
local TableInC_mt = {} -- the class metatable

function TableInC.New()
    local o = {}
    setmetatable(o, {__index = TableInC_mt})
    return o
end
function TableInC.GetRootAsTableInC(buf, offset)
    if type(buf) == "string" then
        buf = flatbuffers.binaryArray.New(buf)
    end
    local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
    local o = TableInC.New()
    o:Init(buf, n + offset)
    return o
end
function TableInC_mt:Init(buf, pos)
    self.view = flatbuffers.view.New(buf, pos)
end
function TableInC_mt:ReferToA1()
    local o = self.view:Offset(4)
    if o ~= 0 then
        local x = self.view:Indirect(o + self.view.pos)
        local obj = require('NamespaceA.TableInFirstNS').New()
        obj:Init(self.view.bytes, x)
        return obj
    end
end
function TableInC_mt:ReferToA2()
    local o = self.view:Offset(6)
    if o ~= 0 then
        local x = self.view:Indirect(o + self.view.pos)
        local obj = require('NamespaceA.SecondTableInA').New()
        obj:Init(self.view.bytes, x)
        return obj
    end
end
function TableInC.Start(builder) builder:StartObject(2) end
function TableInC.AddReferToA1(builder, referToA1) builder:PrependUOffsetTRelativeSlot(0, referToA1, 0) end
function TableInC.AddReferToA2(builder, referToA2) builder:PrependUOffsetTRelativeSlot(1, referToA2, 0) end
function TableInC.End(builder) return builder:EndObject() end

return TableInC -- return the module


InParentNamespace

--[[ MyGame.InParentNamespace

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local InParentNamespace = {}
local mt = {}

function InParentNamespace.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function InParentNamespace.Start(builder)
  builder:StartObject(0)
end

function InParentNamespace.End(builder)
  return builder:EndObject()
end

return InParentNamespace


Monster

--[[ MyGame.Example2.Monster

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Monster = {}
local mt = {}

function Monster.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function Monster.Start(builder)
  builder:StartObject(0)
end

function Monster.End(builder)
  return builder:EndObject()
end

return Monster


Unused

--[[ MyGame.OtherNameSpace.Unused

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //include_test/sub/include_test2.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Unused = {}
local mt = {}

function Unused.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:A()
  return self.view:Get(flatbuffers.N.Int32, self.view.pos + 0)
end

function Unused.CreateUnused(builder, a)
  builder:Prep(4, 4)
  builder:PrependInt32(a)
  return builder:Offset()
end

return Unused


FromInclude

--[[ MyGame.OtherNameSpace.FromInclude

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //include_test/sub/include_test2.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local FromInclude = {
  IncludeVal = 0,
}

return FromInclude


TableB

--[[ MyGame.OtherNameSpace.TableB

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //include_test/sub/include_test2.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local __TableA = require('TableA')
local flatbuffers = require('flatbuffers')

local TableB = {}
local mt = {}

function TableB.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:A()
  local o = self.view:Offset(4)
  if o ~= 0 then
    local x = self.view:Indirect(self.view.pos + o)
    local obj = __TableA.New()
    obj:Init(self.view.bytes, x)
    return obj
  end
end

function TableB.Start(builder)
  builder:StartObject(1)
end

function TableB.AddA(builder, a)
  builder:PrependStructSlot(0, a, 0)
end

function TableB.End(builder)
  return builder:EndObject()
end

return TableB


Stat

--[[ MyGame.Example.Stat

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Stat = {}
local mt = {}

function Stat.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Id()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:String(self.view.pos + o)
  end
end

function mt:Val()
  local o = self.view:Offset(6)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int64, self.view.pos + o)
  end
  return 0
end

function mt:Count()
  local o = self.view:Offset(8)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint16, self.view.pos + o)
  end
  return 0
end

function Stat.Start(builder)
  builder:StartObject(3)
end

function Stat.AddId(builder, id)
  builder:PrependUOffsetTRelativeSlot(0, id, 0)
end

function Stat.AddVal(builder, val)
  builder:PrependInt64Slot(1, val, 0)
end

function Stat.AddCount(builder, count)
  builder:PrependUint16Slot(2, count, 0)
end

function Stat.End(builder)
  return builder:EndObject()
end

return Stat


Test

--[[ MyGame.Example.Test

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local Test = {}
local mt = {}

function Test.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:A()
  return self.view:Get(flatbuffers.N.Int16, self.view.pos + 0)
end

function mt:B()
  return self.view:Get(flatbuffers.N.Int8, self.view.pos + 2)
end

function Test.CreateTest(builder, a, b)
  builder:Prep(2, 4)
  builder:Pad(1)
  builder:PrependInt8(b)
  builder:PrependInt16(a)
  return builder:Offset()
end

return Test


TestSimpleTableWithEnum

--[[ MyGame.Example.TestSimpleTableWithEnum

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local TestSimpleTableWithEnum = {}
local mt = {}

function TestSimpleTableWithEnum.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:Color()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 2
end

function TestSimpleTableWithEnum.Start(builder)
  builder:StartObject(1)
end

function TestSimpleTableWithEnum.AddColor(builder, color)
  builder:PrependUint8Slot(0, color, 2)
end

function TestSimpleTableWithEnum.End(builder)
  return builder:EndObject()
end

return TestSimpleTableWithEnum


LongEnum

--[[ MyGame.Example.LongEnum

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local LongEnum = {
  LongOne = 2,
  LongTwo = 4,
  LongBig = 1099511627776,
}

return LongEnum


TypeAliases

--[[ MyGame.Example.TypeAliases

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local TypeAliases = {}
local mt = {}

function TypeAliases.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:I8()
  local o = self.view:Offset(4)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int8, self.view.pos + o)
  end
  return 0
end

function mt:U8()
  local o = self.view:Offset(6)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint8, self.view.pos + o)
  end
  return 0
end

function mt:I16()
  local o = self.view:Offset(8)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int16, self.view.pos + o)
  end
  return 0
end

function mt:U16()
  local o = self.view:Offset(10)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint16, self.view.pos + o)
  end
  return 0
end

function mt:I32()
  local o = self.view:Offset(12)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int32, self.view.pos + o)
  end
  return 0
end

function mt:U32()
  local o = self.view:Offset(14)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint32, self.view.pos + o)
  end
  return 0
end

function mt:I64()
  local o = self.view:Offset(16)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Int64, self.view.pos + o)
  end
  return 0
end

function mt:U64()
  local o = self.view:Offset(18)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Uint64, self.view.pos + o)
  end
  return 0
end

function mt:F32()
  local o = self.view:Offset(20)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float32, self.view.pos + o)
  end
  return 0.0
end

function mt:F64()
  local o = self.view:Offset(22)
  if o ~= 0 then
    return self.view:Get(flatbuffers.N.Float64, self.view.pos + o)
  end
  return 0.0
end

function mt:V8(j)
  local o = self.view:Offset(24)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Int8, a + ((j-1) * 1))
  end
  return 0
end

function mt:V8AsString(start, stop)
  return self.view:VectorAsString(24, start, stop)
end

function mt:V8Length()
  local o = self.view:Offset(24)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function mt:Vf64(j)
  local o = self.view:Offset(26)
  if o ~= 0 then
    local a = self.view:Vector(o)
    return self.view:Get(flatbuffers.N.Float64, a + ((j-1) * 8))
  end
  return 0
end

function mt:Vf64Length()
  local o = self.view:Offset(26)
  if o ~= 0 then
    return self.view:VectorLen(o)
  end
  return 0
end

function TypeAliases.Start(builder)
  builder:StartObject(12)
end

function TypeAliases.AddI8(builder, i8)
  builder:PrependInt8Slot(0, i8, 0)
end

function TypeAliases.AddU8(builder, u8)
  builder:PrependUint8Slot(1, u8, 0)
end

function TypeAliases.AddI16(builder, i16)
  builder:PrependInt16Slot(2, i16, 0)
end

function TypeAliases.AddU16(builder, u16)
  builder:PrependUint16Slot(3, u16, 0)
end

function TypeAliases.AddI32(builder, i32)
  builder:PrependInt32Slot(4, i32, 0)
end

function TypeAliases.AddU32(builder, u32)
  builder:PrependUint32Slot(5, u32, 0)
end

function TypeAliases.AddI64(builder, i64)
  builder:PrependInt64Slot(6, i64, 0)
end

function TypeAliases.AddU64(builder, u64)
  builder:PrependUint64Slot(7, u64, 0)
end

function TypeAliases.AddF32(builder, f32)
  builder:PrependFloat32Slot(8, f32, 0.0)
end

function TypeAliases.AddF64(builder, f64)
  builder:PrependFloat64Slot(9, f64, 0.0)
end

function TypeAliases.AddV8(builder, v8)
  builder:PrependUOffsetTRelativeSlot(10, v8, 0)
end

function TypeAliases.StartV8Vector(builder, numElems)
  return builder:StartVector(1, numElems, 1)
end

function TypeAliases.AddVf64(builder, vf64)
  builder:PrependUOffsetTRelativeSlot(11, vf64, 0)
end

function TypeAliases.StartVf64Vector(builder, numElems)
  return builder:StartVector(8, numElems, 8)
end

function TypeAliases.End(builder)
  return builder:EndObject()
end

return TypeAliases


StructOfStructs

--[[ MyGame.Example.StructOfStructs

  Automatically generated by the FlatBuffers compiler, do not modify.
  Or modify. I'm a message, not a cop.

  flatc version: 23.5.9

  Declared by  : //monster_test.fbs
  Rooting type : MyGame.Example.Monster (//monster_test.fbs)

--]]

local flatbuffers = require('flatbuffers')

local StructOfStructs = {}
local mt = {}

function StructOfStructs.New()
  local o = {}
  setmetatable(o, {__index = mt})
  return o
end

function mt:Init(buf, pos)
  self.view = flatbuffers.view.New(buf, pos)
end

function mt:A(obj)
  obj:Init(self.view.bytes, self.view.pos + 0)
  return obj
end

function mt:B(obj)
  obj:Init(self.view.bytes, self.view.pos + 8)
  return obj
end

function mt:C(obj)
  obj:Init(self.view.bytes, self.view.pos + 12)
  return obj
end

function StructOfStructs.CreateStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance)
  builder:Prep(4, 20)
  builder:Prep(4, 8)
  builder:PrependUint32(c_distance)
  builder:PrependUint32(c_id)
  builder:Prep(2, 4)
  builder:Pad(1)
  builder:PrependInt8(b_b)
  builder:PrependInt16(b_a)
  builder:Prep(4, 8)
  builder:PrependUint32(a_distance)
  builder:PrependUint32(a_id)
  return builder:Offset()
end

return StructOfStructs