Home | History | Annotate | Download | only in Sample
      1 -- automatically generated by the FlatBuffers compiler, do not modify
      2 
      3 -- namespace: Sample
      4 
      5 local flatbuffers = require('flatbuffers')
      6 
      7 local Monster = {} -- the module
      8 local Monster_mt = {} -- the class metatable
      9 
     10 function Monster.New()
     11     local o = {}
     12     setmetatable(o, {__index = Monster_mt})
     13     return o
     14 end
     15 function Monster.GetRootAsMonster(buf, offset)
     16     local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
     17     local o = Monster.New()
     18     o:Init(buf, n + offset)
     19     return o
     20 end
     21 function Monster_mt:Init(buf, pos)
     22     self.view = flatbuffers.view.New(buf, pos)
     23 end
     24 function Monster_mt:Pos()
     25     local o = self.view:Offset(4)
     26     if o ~= 0 then
     27         local x = o + self.view.pos
     28         local obj = require('MyGame.Sample.Vec3').New()
     29         obj:Init(self.view.bytes, x)
     30         return obj
     31     end
     32 end
     33 function Monster_mt:Mana()
     34     local o = self.view:Offset(6)
     35     if o ~= 0 then
     36         return self.view:Get(flatbuffers.N.Int16, o + self.view.pos)
     37     end
     38     return 150
     39 end
     40 function Monster_mt:Hp()
     41     local o = self.view:Offset(8)
     42     if o ~= 0 then
     43         return self.view:Get(flatbuffers.N.Int16, o + self.view.pos)
     44     end
     45     return 100
     46 end
     47 function Monster_mt:Name()
     48     local o = self.view:Offset(10)
     49     if o ~= 0 then
     50         return self.view:String(o + self.view.pos)
     51     end
     52 end
     53 function Monster_mt:Inventory(j)
     54     local o = self.view:Offset(14)
     55     if o ~= 0 then
     56         local a = self.view:Vector(o)
     57         return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1))
     58     end
     59     return 0
     60 end
     61 function Monster_mt:InventoryLength()
     62     local o = self.view:Offset(14)
     63     if o ~= 0 then
     64         return self.view:VectorLen(o)
     65     end
     66     return 0
     67 end
     68 function Monster_mt:Color()
     69     local o = self.view:Offset(16)
     70     if o ~= 0 then
     71         return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
     72     end
     73     return 2
     74 end
     75 function Monster_mt:Weapons(j)
     76     local o = self.view:Offset(18)
     77     if o ~= 0 then
     78         local x = self.view:Vector(o)
     79         x = x + ((j-1) * 4)
     80         x = self.view:Indirect(x)
     81         local obj = require('MyGame.Sample.Weapon').New()
     82         obj:Init(self.view.bytes, x)
     83         return obj
     84     end
     85 end
     86 function Monster_mt:WeaponsLength()
     87     local o = self.view:Offset(18)
     88     if o ~= 0 then
     89         return self.view:VectorLen(o)
     90     end
     91     return 0
     92 end
     93 function Monster_mt:EquippedType()
     94     local o = self.view:Offset(20)
     95     if o ~= 0 then
     96         return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
     97     end
     98     return 0
     99 end
    100 function Monster_mt:Equipped()
    101     local o = self.view:Offset(22)
    102     if o ~= 0 then
    103         local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
    104         self.view:Union(obj, o)
    105         return obj
    106     end
    107 end
    108 function Monster.Start(builder) builder:StartObject(10) end
    109 function Monster.AddPos(builder, pos) builder:PrependStructSlot(0, pos, 0) end
    110 function Monster.AddMana(builder, mana) builder:PrependInt16Slot(1, mana, 150) end
    111 function Monster.AddHp(builder, hp) builder:PrependInt16Slot(2, hp, 100) end
    112 function Monster.AddName(builder, name) builder:PrependUOffsetTRelativeSlot(3, name, 0) end
    113 function Monster.AddInventory(builder, inventory) builder:PrependUOffsetTRelativeSlot(5, inventory, 0) end
    114 function Monster.StartInventoryVector(builder, numElems) return builder:StartVector(1, numElems, 1) end
    115 function Monster.AddColor(builder, color) builder:PrependInt8Slot(6, color, 2) end
    116 function Monster.AddWeapons(builder, weapons) builder:PrependUOffsetTRelativeSlot(7, weapons, 0) end
    117 function Monster.StartWeaponsVector(builder, numElems) return builder:StartVector(4, numElems, 4) end
    118 function Monster.AddEquippedType(builder, equippedType) builder:PrependUint8Slot(8, equippedType, 0) end
    119 function Monster.AddEquipped(builder, equipped) builder:PrependUOffsetTRelativeSlot(9, equipped, 0) end
    120 function Monster.End(builder) return builder:EndObject() end
    121 
    122 return Monster -- return the module