• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:local

2 local compat = require("flatbuffers.compat")
4 local performBenchmarkTests = false
15 local function checkReadBuffer(buf, offset, sizePrefix)
23 local size = flatbuffers.N.Int32:Unpack(buf, offset)
24 assert(size == buf.size - offset - 4)
28 local mon = monster.GetRootAsMonster(buf, offset)
34 local vec = assert(mon:Pos(), "Monster Position is nil")
41 local t = require("MyGame.Example.Test").New()
47 local ut = require("MyGame.Example.Any")
50 local table2 = mon:Test()
53 local mon2 = monster.New()
59 local invsum = 0
61 local v = mon:Inventory(i)
67 assert(mon:VectorOfLongs(i) == 10^((i-1)*2))
70 local dbls = { -1.7976931348623157e+308, 0, 1.7976931348623157e+308}
77 local test0 = mon:Test4(1)
78 local test1 = mon:Test4(2)
80 local v0 = test0:A()
81 local v1 = test0:B()
82 local v2 = test1:A()
83 local v3 = test1:B()
85 local sumtest12 = v0 + v1 + v2 + v3
97 local function generateMonster(sizePrefix, b)
100 local str = b:CreateString("MyMonster")
101 local test1 = b:CreateString("test1")
102 local test2 = b:CreateString("test2")
103 local fred = b:CreateString("Fred")
111 local inv = b:EndVector(5)
115 local mon2 = monster.End(b)
120 local test4 = b:EndVector(2)
125 local testArrayOfString = b:EndVector(2)
133 local vectorOfLongs = b:EndVector(5)
138 b:PrependFloat64(-1.7976931348623157e+308)
139 local vectorOfDoubles = b:EndVector(3)
142 local pos = vec3.CreateVec3(b, 1.0, 2.0, 3.0, 3.0, 2, 5, 6)
158 local mon = monster.End(b)
168 local function sizePrefix(sizePrefix)
169 local buf,offset = generateMonster(sizePrefix)
173 local function fbbClear()
174 -- Generate a builder that will be 'cleared' and reused to create two different objects.
175 local fbb = flatbuffers.Builder(0)
177 -- First use the builder to read the normal monster data and verify it works
178 local buf, offset = generateMonster(false, fbb)
181 -- Then clear the builder to be used again
184 -- Storage for the built monsters
185 local monsters = {}
186 local lastBuf
188-- Make another builder that will be use identically to the 'cleared' one so outputs can be compar…
189 -- Cleared builder and new builder in the exact same way, so we can compare their results
191 local strOffset = builder:CreateString("Hi there")
197 local buf = builder:Output(false)
201 -- the output, sized-buffer should be identical
207 -- Check that all the fields for the generated monsters are as we expect
210-- HP is default to 100 in the schema, but we change it in generateMonster to 80, so this is a goo…
211 -- see if the cleared builder really clears the data.
218 local function testCanonicalData()
219 local f = assert(io.open('monsterdata_test.mon', 'rb'))
220 local wireData = f:read("*a")
225 local function testCreateEmptyString()
226 local b = flatbuffers.Builder(0)
227 local str = b:CreateString("")
231 local s = b:Output()
232 local data = flatbuffers.binaryArray.New(s)
233 local mon = monster.GetRootAsMonster(data, 0)
237 local function benchmarkMakeMonster(count, reuseBuilder)
238 local fbb = reuseBuilder and flatbuffers.Builder(0)
239 local length = #(generateMonster(false, fbb))
241 local s = os.clock()
245 local e = os.clock()
247 local dur = (e - s)
248 local rate = count / (dur * 1000)
249 local data = (length * count) / (1024 * 1024)
250 local dataRate = data / dur
252 print(string.format('built %d %d-byte flatbuffers in %.2fsec: %.2f/msec, %.2fMB/sec',
256 local function benchmarkReadBuffer(count)
257 local f = assert(io.open('monsterdata_test.mon', 'rb'))
258 local buf = f:read("*a")
261 local s = os.clock()
265 local e = os.clock()
267 local dur = (e - s)
268 local rate = count / (dur * 1000)
269 local data = (#buf * count) / (1024 * 1024)
270 local dataRate = data / dur
272 print(string.format('traversed %d %d-byte flatbuffers in %.2fsec: %.2f/msec, %.2fMB/sec',
276 local function getRootAs_canAcceptString()
277 local f = assert(io.open('monsterdata_test.mon', 'rb'))
278 local wireData = f:read("*a")
281 local mon = monster.GetRootAsMonster(wireData, 0)
285 local function testAccessByteVectorAsString()
286 local f = assert(io.open('monsterdata_test.mon', 'rb'))
287 local wireData = f:read("*a")
289 local mon = monster.GetRootAsMonster(wireData, 0)
290 -- the data of byte array Inventory is [0, 1, 2, 3, 4]
291 local s = mon:InventoryAsString(1, 3)
294 assert(string.byte(s, i) == i - 1)
297 local s = mon:InventoryAsString(2, 5)
303 local s = mon:InventoryAsString(5, 5)
307 local s = mon:InventoryAsString(2)
313 local s = mon:InventoryAsString()
316 assert(string.byte(s, i) == i - 1)
320 local tests =
349 local benchmarks =
368 -- uncomment following to run 1 million to compare.
369 -- Took ~141 seconds on my machine
370 --{1000000},
375 local result, err = xpcall(function()
381 local function buildArgList(tbl)
382 local s = ""
386 return s:sub(1,-2)
395 local testsPassed, testsFailed = 0,0
397 local allargs = test.args or {{}}
399 local results, err = xpcall(test.f,debug.traceback, table.unpack(args))
412 local totalTests = testsPassed + testsFailed
428 os.exit(result and 0 or -1)