mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 06:57:31 +00:00
Lua (5.3) Language addition (#4804)
* starting Lua port of python implmention. Syncing commit * Bulk of Lua module port from Python done. Not tested, only static analysis. Need to work on binary strings. Started work on flatc lua code generation * Fixed all the basic errors to produced a binary output from the builder, don't know if it is generated correctly, but it contains data, so that must be good * fixed binary set command that was extending the array improperly * continued improvement * Moved lua submodules down a directory so their names don't clash with potential other modules. Added compat module to provide Lua versioning logic * Successful sample port from Python * working on testing Lua code with formal tests * continued to work on tests and fixes to code to make tests pass * Added reading buffer test * Changed binaryarray implmentation to use a temporary table for storing data, and then serialize it to a string when requested. This double the rate of building flatbuffers compared to the string approach. * Didn't need encode module as it just added another layer of indirection that isn't need * profiled reading buffers, optimizations to increase read performance of monster data to ~7 monster / millisecond * Writing profiler improvments. Get about ~2 monsters/millisecond building rate * removed Numpy generation from Lua (came from the Python port) * math.pow is deprecated in Lua 5.3, so changed to ^ notation. Also added .bat script for starting Lua tests * adding results of generate_code.bat * simple edits for code review in PR. * There was a buffer overflow in inserting the keywords into the unorder set for both the Lua and Python code gens. Changed insertion to use iterators. * fixed spacing issue * basic documenation/tutorial updates. Updated sample_binary.lua to reflect the tutorial better * removed windows-specific build step in Lua tests
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
8ea293b988
commit
ba5eb3b5cf
6
tests/LuaTest.bat
Normal file
6
tests/LuaTest.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
set buildtype=Release
|
||||
if "%1"=="-b" set buildtype=%2
|
||||
|
||||
..\%buildtype%\flatc.exe --lua -I include_test monster_test.fbs
|
||||
|
||||
lua53.exe luatest.lua
|
||||
31
tests/MyGame/Example/Ability.lua
Normal file
31
tests/MyGame/Example/Ability.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Ability = {} -- the module
|
||||
local Ability_mt = {} -- the class metatable
|
||||
|
||||
function Ability.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Ability_mt})
|
||||
return o
|
||||
end
|
||||
function Ability_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Ability_mt:Id()
|
||||
return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 0)
|
||||
end
|
||||
function Ability_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 -- return the module
|
||||
12
tests/MyGame/Example/Any.lua
Normal file
12
tests/MyGame/Example/Any.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local Any = {
|
||||
NONE = 0,
|
||||
Monster = 1,
|
||||
TestSimpleTableWithEnum = 2,
|
||||
MyGame_Example2_Monster = 3,
|
||||
}
|
||||
|
||||
return Any -- return the module
|
||||
11
tests/MyGame/Example/Color.lua
Normal file
11
tests/MyGame/Example/Color.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local Color = {
|
||||
Red = 1,
|
||||
Green = 2,
|
||||
Blue = 8,
|
||||
}
|
||||
|
||||
return Color -- return the module
|
||||
542
tests/MyGame/Example/Monster.lua
Normal file
542
tests/MyGame/Example/Monster.lua
Normal file
@@ -0,0 +1,542 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
-- /// an example documentation comment: monster object
|
||||
local Monster = {} -- the module
|
||||
local Monster_mt = {} -- the class metatable
|
||||
|
||||
function Monster.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Monster_mt})
|
||||
return o
|
||||
end
|
||||
function Monster.GetRootAsMonster(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = Monster.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function Monster_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Monster_mt:Pos()
|
||||
local o = self.view:Offset(4)
|
||||
if o ~= 0 then
|
||||
local x = o + self.view.pos
|
||||
local obj = require('MyGame.Example.Vec3').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:Mana()
|
||||
local o = self.view:Offset(6)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int16, o + self.view.pos)
|
||||
end
|
||||
return 150
|
||||
end
|
||||
function Monster_mt:Hp()
|
||||
local o = self.view:Offset(8)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int16, o + self.view.pos)
|
||||
end
|
||||
return 100
|
||||
end
|
||||
function Monster_mt:Name()
|
||||
local o = self.view:Offset(10)
|
||||
if o ~= 0 then
|
||||
return self.view:String(o + self.view.pos)
|
||||
end
|
||||
end
|
||||
function Monster_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 Monster_mt:InventoryLength()
|
||||
local o = self.view:Offset(14)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Color()
|
||||
local o = self.view:Offset(16)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
|
||||
end
|
||||
return 8
|
||||
end
|
||||
function Monster_mt:TestType()
|
||||
local o = self.view:Offset(18)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Test()
|
||||
local o = self.view:Offset(20)
|
||||
if o ~= 0 then
|
||||
local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
|
||||
self.view:Union(obj, o)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt: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 = require('MyGame.Example.Test').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:Test4Length()
|
||||
local o = self.view:Offset(22)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_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 Monster_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 = require('MyGame.Example.Monster').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:TestarrayoftablesLength()
|
||||
local o = self.view:Offset(26)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Enemy()
|
||||
local o = self.view:Offset(28)
|
||||
if o ~= 0 then
|
||||
local x = self.view:Indirect(o + self.view.pos)
|
||||
local obj = require('MyGame.Example.Monster').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_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 Monster_mt:TestnestedflatbufferLength()
|
||||
local o = self.view:Offset(30)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testempty()
|
||||
local o = self.view:Offset(32)
|
||||
if o ~= 0 then
|
||||
local x = self.view:Indirect(o + self.view.pos)
|
||||
local obj = require('MyGame.Example.Stat').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:Testbool()
|
||||
local o = self.view:Offset(34)
|
||||
if o ~= 0 then
|
||||
return (self.view:Get(flatbuffers.N.Bool, o + self.view.pos) ~= 0)
|
||||
end
|
||||
return false
|
||||
end
|
||||
function Monster_mt:Testhashs32Fnv1()
|
||||
local o = self.view:Offset(36)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashu32Fnv1()
|
||||
local o = self.view:Offset(38)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashs64Fnv1()
|
||||
local o = self.view:Offset(40)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashu64Fnv1()
|
||||
local o = self.view:Offset(42)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashs32Fnv1a()
|
||||
local o = self.view:Offset(44)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashu32Fnv1a()
|
||||
local o = self.view:Offset(46)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashs64Fnv1a()
|
||||
local o = self.view:Offset(48)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testhashu64Fnv1a()
|
||||
local o = self.view:Offset(50)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:TestarrayofboolsLength()
|
||||
local o = self.view:Offset(52)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:Testf()
|
||||
local o = self.view:Offset(54)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Float32, o + self.view.pos)
|
||||
end
|
||||
return 3.14159
|
||||
end
|
||||
function Monster_mt:Testf2()
|
||||
local o = self.view:Offset(56)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Float32, o + self.view.pos)
|
||||
end
|
||||
return 3.0
|
||||
end
|
||||
function Monster_mt:Testf3()
|
||||
local o = self.view:Offset(58)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Float32, o + self.view.pos)
|
||||
end
|
||||
return 0.0
|
||||
end
|
||||
function Monster_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 Monster_mt:Testarrayofstring2Length()
|
||||
local o = self.view:Offset(60)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 = require('MyGame.Example.Ability').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:TestarrayofsortedstructLength()
|
||||
local o = self.view:Offset(62)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:FlexLength()
|
||||
local o = self.view:Offset(64)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 = require('MyGame.Example.Test').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:Test5Length()
|
||||
local o = self.view:Offset(66)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:VectorOfLongsLength()
|
||||
local o = self.view:Offset(68)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:VectorOfDoublesLength()
|
||||
local o = self.view:Offset(70)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:ParentNamespaceTest()
|
||||
local o = self.view:Offset(72)
|
||||
if o ~= 0 then
|
||||
local x = self.view:Indirect(o + self.view.pos)
|
||||
local obj = require('MyGame.InParentNamespace').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_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 = require('MyGame.Example.Referrable').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:VectorOfReferrablesLength()
|
||||
local o = self.view:Offset(74)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:SingleWeakReference()
|
||||
local o = self.view:Offset(76)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:VectorOfWeakReferencesLength()
|
||||
local o = self.view:Offset(78)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 = require('MyGame.Example.Referrable').New()
|
||||
obj:Init(self.view.bytes, x)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function Monster_mt:VectorOfStrongReferrablesLength()
|
||||
local o = self.view:Offset(80)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:CoOwningReference()
|
||||
local o = self.view:Offset(82)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:VectorOfCoOwningReferencesLength()
|
||||
local o = self.view:Offset(84)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_mt:NonOwningReference()
|
||||
local o = self.view:Offset(86)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster_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 Monster_mt:VectorOfNonOwningReferencesLength()
|
||||
local o = self.view:Offset(88)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Monster.Start(builder) builder:StartObject(43) 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:PrependInt8Slot(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:PrependUOffsetTRelativeSlot(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:PrependUOffsetTRelativeSlot(14, testempty, 0) end
|
||||
function Monster.AddTestbool(builder, testbool) builder:PrependBoolSlot(15, testbool, 0) 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:PrependUOffsetTRelativeSlot(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.End(builder) return builder:EndObject() end
|
||||
|
||||
return Monster -- return the module
|
||||
35
tests/MyGame/Example/Referrable.lua
Normal file
35
tests/MyGame/Example/Referrable.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Referrable = {} -- the module
|
||||
local Referrable_mt = {} -- the class metatable
|
||||
|
||||
function Referrable.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Referrable_mt})
|
||||
return o
|
||||
end
|
||||
function Referrable.GetRootAsReferrable(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = Referrable.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function Referrable_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Referrable_mt:Id()
|
||||
local o = self.view:Offset(4)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
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 -- return the module
|
||||
50
tests/MyGame/Example/Stat.lua
Normal file
50
tests/MyGame/Example/Stat.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Stat = {} -- the module
|
||||
local Stat_mt = {} -- the class metatable
|
||||
|
||||
function Stat.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Stat_mt})
|
||||
return o
|
||||
end
|
||||
function Stat.GetRootAsStat(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = Stat.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function Stat_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Stat_mt:Id()
|
||||
local o = self.view:Offset(4)
|
||||
if o ~= 0 then
|
||||
return self.view:String(o + self.view.pos)
|
||||
end
|
||||
end
|
||||
function Stat_mt:Val()
|
||||
local o = self.view:Offset(6)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function Stat_mt:Count()
|
||||
local o = self.view:Offset(8)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint16, o + self.view.pos)
|
||||
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 -- return the module
|
||||
32
tests/MyGame/Example/Test.lua
Normal file
32
tests/MyGame/Example/Test.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Test = {} -- the module
|
||||
local Test_mt = {} -- the class metatable
|
||||
|
||||
function Test.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Test_mt})
|
||||
return o
|
||||
end
|
||||
function Test_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Test_mt:A()
|
||||
return self.view:Get(flatbuffers.N.Int16, self.view.pos + 0)
|
||||
end
|
||||
function Test_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 -- return the module
|
||||
35
tests/MyGame/Example/TestSimpleTableWithEnum.lua
Normal file
35
tests/MyGame/Example/TestSimpleTableWithEnum.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local TestSimpleTableWithEnum = {} -- the module
|
||||
local TestSimpleTableWithEnum_mt = {} -- the class metatable
|
||||
|
||||
function TestSimpleTableWithEnum.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = TestSimpleTableWithEnum_mt})
|
||||
return o
|
||||
end
|
||||
function TestSimpleTableWithEnum.GetRootAsTestSimpleTableWithEnum(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = TestSimpleTableWithEnum.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function TestSimpleTableWithEnum_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function TestSimpleTableWithEnum_mt:Color()
|
||||
local o = self.view:Offset(4)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
|
||||
end
|
||||
return 2
|
||||
end
|
||||
function TestSimpleTableWithEnum.Start(builder) builder:StartObject(1) end
|
||||
function TestSimpleTableWithEnum.AddColor(builder, color) builder:PrependInt8Slot(0, color, 2) end
|
||||
function TestSimpleTableWithEnum.End(builder) return builder:EndObject() end
|
||||
|
||||
return TestSimpleTableWithEnum -- return the module
|
||||
141
tests/MyGame/Example/TypeAliases.lua
Normal file
141
tests/MyGame/Example/TypeAliases.lua
Normal file
@@ -0,0 +1,141 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local TypeAliases = {} -- the module
|
||||
local TypeAliases_mt = {} -- the class metatable
|
||||
|
||||
function TypeAliases.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = TypeAliases_mt})
|
||||
return o
|
||||
end
|
||||
function TypeAliases.GetRootAsTypeAliases(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = TypeAliases.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function TypeAliases_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function TypeAliases_mt:I8()
|
||||
local o = self.view:Offset(4)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:U8()
|
||||
local o = self.view:Offset(6)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:I16()
|
||||
local o = self.view:Offset(8)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int16, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:U16()
|
||||
local o = self.view:Offset(10)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint16, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:I32()
|
||||
local o = self.view:Offset(12)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:U32()
|
||||
local o = self.view:Offset(14)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint32, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:I64()
|
||||
local o = self.view:Offset(16)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:U64()
|
||||
local o = self.view:Offset(18)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_mt:F32()
|
||||
local o = self.view:Offset(20)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Float32, o + self.view.pos)
|
||||
end
|
||||
return 0.0
|
||||
end
|
||||
function TypeAliases_mt:F64()
|
||||
local o = self.view:Offset(22)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Float64, o + self.view.pos)
|
||||
end
|
||||
return 0.0
|
||||
end
|
||||
function TypeAliases_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 TypeAliases_mt:V8Length()
|
||||
local o = self.view:Offset(24)
|
||||
if o ~= 0 then
|
||||
return self.view:VectorLen(o)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TypeAliases_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 TypeAliases_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 -- return the module
|
||||
54
tests/MyGame/Example/Vec3.lua
Normal file
54
tests/MyGame/Example/Vec3.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Vec3 = {} -- the module
|
||||
local Vec3_mt = {} -- the class metatable
|
||||
|
||||
function Vec3.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Vec3_mt})
|
||||
return o
|
||||
end
|
||||
function Vec3_mt:Init(buf, pos)
|
||||
self.view = flatbuffers.view.New(buf, pos)
|
||||
end
|
||||
function Vec3_mt:X()
|
||||
return self.view:Get(flatbuffers.N.Float32, self.view.pos + 0)
|
||||
end
|
||||
function Vec3_mt:Y()
|
||||
return self.view:Get(flatbuffers.N.Float32, self.view.pos + 4)
|
||||
end
|
||||
function Vec3_mt:Z()
|
||||
return self.view:Get(flatbuffers.N.Float32, self.view.pos + 8)
|
||||
end
|
||||
function Vec3_mt:Test1()
|
||||
return self.view:Get(flatbuffers.N.Float64, self.view.pos + 16)
|
||||
end
|
||||
function Vec3_mt:Test2()
|
||||
return self.view:Get(flatbuffers.N.Int8, self.view.pos + 24)
|
||||
end
|
||||
function Vec3_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(16, 32)
|
||||
builder:Pad(2)
|
||||
builder:Prep(2, 4)
|
||||
builder:Pad(1)
|
||||
builder:PrependInt8(test3_b)
|
||||
builder:PrependInt16(test3_a)
|
||||
builder:Pad(1)
|
||||
builder:PrependInt8(test2)
|
||||
builder:PrependFloat64(test1)
|
||||
builder:Pad(4)
|
||||
builder:PrependFloat32(z)
|
||||
builder:PrependFloat32(y)
|
||||
builder:PrependFloat32(x)
|
||||
return builder:Offset()
|
||||
end
|
||||
|
||||
return Vec3 -- return the module
|
||||
27
tests/MyGame/Example2/Monster.lua
Normal file
27
tests/MyGame/Example2/Monster.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example2
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local Monster = {} -- the module
|
||||
local Monster_mt = {} -- the class metatable
|
||||
|
||||
function Monster.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = Monster_mt})
|
||||
return o
|
||||
end
|
||||
function Monster.GetRootAsMonster(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = Monster.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function Monster_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 -- return the module
|
||||
27
tests/MyGame/InParentNamespace.lua
Normal file
27
tests/MyGame/InParentNamespace.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: MyGame
|
||||
|
||||
local flatbuffers = require('flatbuffers')
|
||||
|
||||
local InParentNamespace = {} -- the module
|
||||
local InParentNamespace_mt = {} -- the class metatable
|
||||
|
||||
function InParentNamespace.New()
|
||||
local o = {}
|
||||
setmetatable(o, {__index = InParentNamespace_mt})
|
||||
return o
|
||||
end
|
||||
function InParentNamespace.GetRootAsInParentNamespace(buf, offset)
|
||||
local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
|
||||
local o = InParentNamespace.New()
|
||||
o:Init(buf, n + offset)
|
||||
return o
|
||||
end
|
||||
function InParentNamespace_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 -- return the module
|
||||
@@ -15,8 +15,8 @@
|
||||
set buildtype=Release
|
||||
if "%1"=="-b" set buildtype=%2
|
||||
|
||||
..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --js --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json
|
||||
..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --js --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
|
||||
..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --lua --js --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json
|
||||
..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --lua --js --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
|
||||
..\%buildtype%\flatc.exe --cpp --js --ts --php --gen-mutable --reflect-names --gen-object-api --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs
|
||||
..\%buildtype%\flatc.exe -b --schema --bfbs-comments -I include_test monster_test.fbs
|
||||
..\%buildtype%\flatc.exe --jsonschema --schema -I include_test monster_test.fbs
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
../flatc --cpp --java --csharp --dart --go --binary --python --js --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json
|
||||
../flatc --cpp --java --csharp --dart --go --binary --python --js --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
|
||||
../flatc --cpp --java --csharp --dart --go --binary --lua --python --js --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json
|
||||
../flatc --cpp --java --csharp --dart --go --binary --lua --python --js --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
|
||||
../flatc --cpp --js --ts --php --gen-mutable --reflect-names --gen-object-api --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs
|
||||
../flatc -b --schema --bfbs-comments -I include_test monster_test.fbs
|
||||
../flatc --jsonschema --schema -I include_test monster_test.fbs
|
||||
|
||||
294
tests/luatest.lua
Normal file
294
tests/luatest.lua
Normal file
@@ -0,0 +1,294 @@
|
||||
package.path = string.format("../lua/?.lua;./?.lua;%s",package.path)
|
||||
|
||||
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)
|
||||
-- no longer matches python tests, but the latest 'monsterdata_test.mon'
|
||||
-- is 448 bytes, minus 4 to arrive at the 444
|
||||
assert(size == 444)
|
||||
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")
|
||||
|
||||
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)
|
||||
local b = 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.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 testCanonicalData()
|
||||
local f = assert(io.open('monsterdata_test.mon', 'rb'))
|
||||
local wireData = f:read("*a")
|
||||
f:close()
|
||||
checkReadBuffer(wireData)
|
||||
end
|
||||
|
||||
local function benchmarkMakeMonster(count)
|
||||
local length = #(generateMonster())
|
||||
|
||||
--require("flatbuffers.profiler")
|
||||
--profiler = newProfiler("call")
|
||||
--profiler:start()
|
||||
|
||||
local s = os.clock()
|
||||
for i=1,count do
|
||||
generateMonster()
|
||||
end
|
||||
local e = os.clock()
|
||||
|
||||
--profiler:stop()
|
||||
|
||||
--local outfile = io.open( "profile.txt", "w+" )
|
||||
--profiler:report( outfile, true)
|
||||
--outfile:close()
|
||||
|
||||
|
||||
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 tests =
|
||||
{
|
||||
{
|
||||
f = sizePrefix,
|
||||
d = "Test size prefix",
|
||||
args = {{true}, {false}}
|
||||
},
|
||||
{
|
||||
f = testCanonicalData,
|
||||
d = "Tests Canonical flatbuffer file included in repo"
|
||||
},
|
||||
{
|
||||
f = benchmarkMakeMonster,
|
||||
d = "Benchmark making monsters",
|
||||
args = {
|
||||
{100},
|
||||
{1000},
|
||||
{10000},
|
||||
}
|
||||
},
|
||||
{
|
||||
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
|
||||
|
||||
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 or -1)
|
||||
Reference in New Issue
Block a user