-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathluacov.report.out
2064 lines (1692 loc) · 64.1 KB
/
luacov.report.out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
==============================================================================
./knife/base.lua
==============================================================================
1 return {
extend = function (self, subtype)
18 subtype = subtype or {}
18 local meta = { __index = subtype }
36 return setmetatable(subtype, {
18 __index = self,
__call = function (self, ...)
8 local instance = setmetatable({}, meta)
8 return instance, instance:constructor(...)
end
18 })
end,
5 constructor = function () end,
1 }
==============================================================================
./knife/behavior.lua
==============================================================================
-- behavior.lua -- a state manager
-- internal/external api
local function getCurrentFrame (behavior)
18 return behavior.states[behavior.state][behavior.index]
end
local function advanceFrame (behavior)
12 local nextState = behavior.frame.after
12 local nextIndex = behavior.index + 1
12 local maxIndex = #behavior.states[behavior.state]
12 if nextState then
2 behavior.state = nextState
2 nextIndex = 1
10 elseif nextIndex > maxIndex then
2 nextIndex = 1
end
12 behavior.index = nextIndex
12 behavior.frame = behavior:getCurrentFrame()
end
local function performAction (behavior)
18 local act = behavior.frame.action
18 if act then
2 act(behavior, behavior.subject)
end
end
-- external api
local function update (behavior, dt)
3 behavior.elapsed = behavior.elapsed + dt
15 while behavior.elapsed >= behavior.frame.duration do
12 behavior.elapsed = behavior.elapsed - behavior.frame.duration
12 behavior:advanceFrame()
12 behavior:performAction()
end
3 return behavior
end
local function setState (behavior, state, index)
1 behavior.state = state
1 behavior.index = index or 1
1 behavior.elapsed = 0
1 behavior.frame = behavior:getCurrentFrame()
1 behavior:performAction()
1 return behavior
end
-- behavior factory
return function (states, subject)
5 local behavior = {
5 states = states,
5 subject = subject,
5 elapsed = 0,
5 state = 'default',
5 index = 1,
-- internal api
5 getCurrentFrame = getCurrentFrame,
5 advanceFrame = advanceFrame,
5 performAction = performAction,
-- external api
5 update = update,
5 setState = setState
}
5 behavior.frame = behavior:getCurrentFrame()
5 behavior:performAction()
5 return behavior
end
==============================================================================
./knife/bind.lua
==============================================================================
1 local loadstring = _G.loadstring or _G.load
1 local tconcat = table.concat
1 local helperCache = {}
local function buildHelper (argCount)
3 if helperCache[argCount] then
1 return helperCache[argCount]
end
2 local argList1 = { 'f' }
2 local argList2 = {}
4 for index = 1, argCount do
2 argList1[index + 1] = 'a' .. index
2 argList2[index] = 'a' .. index
end
2 argList2[argCount + 1] = '...'
2 local source = 'return function(' .. tconcat(argList1, ', ') ..
2 ') return function(...) return f(' .. tconcat(argList2, ', ') ..
2 ') end end'
2 local helper = loadstring(source)()
2 helperCache[argCount] = helper
2 return helper
end
return function (func, ...)
3 return buildHelper(select('#', ...))(func, ...)
end
==============================================================================
./knife/chain.lua
==============================================================================
local function Invoker (links, index)
return function (...)
16 local link = links[index]
16 if not link then
1 return
end
15 local continue = Invoker(links, index + 1)
15 local returned = link(continue, ...)
15 if returned then
4 returned(function (_, ...) continue(...) end)
end
end
end
return function (...)
7 local links = { ... }
local function chain (...)
14 if not (...) then
5 return Invoker(links, 1)(select(2, ...))
end
9 local offset = #links
19 for index = 1, select('#', ...) do
10 links[offset + index] = select(index, ...)
end
9 return chain
end
7 return chain
end
==============================================================================
./knife/convoke.lua
==============================================================================
return function (routine)
4 local routines = { routine }
4 local routineIndex = 1
4 local isFinished = false
local function execute ()
5 local continueCount = 0
local run
local function continue ()
8 continueCount = continueCount + 1
return function (...)
8 continueCount = continueCount - 1
8 if continueCount == 0 then
7 return run(...)
end
end
end
local function wait (...)
7 return coroutine.yield(...)
end
10 local r = coroutine.create(function ()
5 isFinished = false
11 while routineIndex <= #routines do
6 routines[routineIndex](continue, wait)
6 continueCount = 0
6 routineIndex = routineIndex + 1
end
5 isFinished = true
end)
run = function (...)
12 return coroutine.resume(r, ...)
end
5 run()
end
local function appendOrExecute (routine)
6 if routine then
2 routines[#routines + 1] = routine
2 if isFinished then
1 execute()
end
2 return appendOrExecute
else
4 execute()
end
end
4 return appendOrExecute
end
==============================================================================
./knife/event.lua
==============================================================================
-- Event module
1 local Event = {}
-- Event handler registry
1 Event.handlers = {}
-- Remove an event handler from the registry
local function remove (self)
5 if not self.isRegistered then
1 return self
end
4 if self.prevHandler then
1 self.prevHandler.nextHandler = self.nextHandler
end
4 if self.nextHandler then
1 self.nextHandler.prevHandler = self.prevHandler
end
4 if Event.handlers[self.name] == self then
3 Event.handlers[self.name] = self.nextHandler
end
4 self.prevHandler = nil
4 self.nextHandler = nil
4 self.isRegistered = false
4 return self
end
-- Insert an event handler into the registry
local function register (self)
20 if self.isRegistered then
1 return self
end
19 self.nextHandler = Event.handlers[self.name]
19 if self.nextHandler then
6 self.nextHandler.prevHandler = self
end
19 Event.handlers[self.name] = self
19 self.isRegistered = true
19 return self
end
-- Create an event handler
local function Handler (name, callback)
19 return {
19 name = name,
19 callback = callback,
19 isRegistered = false,
19 remove = remove,
19 register = register
19 }
end
-- Create and register a new event handler
1 function Event.on (name, callback)
19 return register(Handler(name, callback))
end
-- Dispatch an event
1 function Event.dispatch (name, ...)
10 local handler = Event.handlers[name]
18 while handler do
9 if handler.callback(...) == false then
1 return handler
end
8 handler = handler.nextHandler
end
end
local function isCallable (value)
3 return type(value) == 'function' or
3 getmetatable(value) and getmetatable(value).__call
end
-- Inject a dispatcher into a table.
local function hookDispatcher (t, key)
3 local original = t[key]
3 if isCallable(original) then
t[key] = function (...)
1 original(...)
1 return Event.dispatch(key, ...)
end
else
t[key] = function (...)
2 return Event.dispatch(key, ...)
end
end
end
-- Inject dispatchers into a table. Examples:
-- Event.hook(love.handlers)
-- Event.hook(love, { 'load', 'update', 'draw' })
1 function Event.hook (t, keys)
3 if keys then
2 for _, key in ipairs(keys) do
1 hookDispatcher(t, key)
end
else
4 for key in pairs(t) do
2 hookDispatcher(t, key)
end
end
end
1 return Event
==============================================================================
./knife/memoize.lua
==============================================================================
1 local loadstring = _G.loadstring or _G.load
1 local weakKeys = { __mode = 'k' }
1 local cache = setmetatable({}, weakKeys)
1 local resultsKey = {}
1 local nilKey = {}
local function getMetaCall (callable)
64 local meta = getmetatable(callable)
64 return meta and meta.__call
end
1 local tupleConstructorCache = {}
local function buildTupleConstructor (n)
21 if tupleConstructorCache[n] then
18 return tupleConstructorCache[n]
end
3 local t = {}
9 for i = 1, n do
6 t[i] = "a" .. i
end
3 local args = table.concat(t, ',')
6 local ctor = loadstring('return function(' .. args ..
6 ') return function() return ' .. args .. ' end end')()
3 tupleConstructorCache[n] = ctor
3 return ctor
end
local function tuple (...)
21 return buildTupleConstructor(select('#', ...))(...)
end
return function (callable)
54 local metaCall = getMetaCall(callable)
54 if type(callable) ~= 'function' and not metaCall then
4 error 'Attempted to memoize a non-callable value.'
end
50 cache[callable] = setmetatable({}, weakKeys)
local function run (...)
45 local node = cache[callable]
45 local argc = select('#', ...)
116 for i = 1, argc do
71 local key = select(i, ...)
71 if key == nil then
4 key = nilKey
end
71 if not node[key] then
30 node[key] = setmetatable({}, weakKeys)
end
71 node = node[key]
end
45 if not node[resultsKey] then
22 node[resultsKey] = tuple(callable(...))
end
44 return node[resultsKey]()
end
50 if metaCall then
return function (...)
10 local call = getMetaCall(callable)
10 if call ~= metaCall then
2 cache[callable] = setmetatable({}, weakKeys)
2 metaCall = call
end
10 return run(...)
16 end, cache, resultsKey, nilKey
end
34 return run, cache, resultsKey, nilKey
end
==============================================================================
./knife/serialize.lua
==============================================================================
1 local tinsert, tconcat, infinity = table.insert, table.concat, math.huge
return function (value)
2 local intro, outro, ready, known = {}, {}, {}, {}
2 local knownCount = 0
2 local writer = {}
-- get writer delegate for this value's type
local function getWriter (value)
66 return writer[type(value)]
end
-- check if a value has a representation yet
local function isReady (value)
58 return type(value) ~= 'table' or ready[value]
end
-- serialize tables
2 function writer.table (value)
10 if known[value] then
4 return known[value]
end
6 knownCount = knownCount + 1
6 local variable = ('v%i'):format(knownCount)
6 known[value] = variable
6 local parts = {}
38 for k, v in pairs(value) do
32 local writeKey, writeValue = getWriter(k), getWriter(v)
32 if writeKey and writeValue then
30 local key, value = writeKey(k), writeValue(v)
30 if isReady(k) and isReady(v) then
26 tinsert(parts, ('[%s]=%s'):format(key, value))
else
4 tinsert(outro, ('%s[%s]=%s'):format(variable, key, value))
end
end
end
6 local fields = tconcat(parts, ',')
6 tinsert(intro, ('local %s={%s}'):format(variable, fields))
6 ready[value] = true
6 return variable
end
-- preserve sign bit on NaN, since Lua prints "nan" or "-nan"
local function writeNan (n)
4 return tostring(n) == tostring(0/0) and '0/0' or '-(0/0)'
end
-- serialize numbers
2 function writer.number (value)
26 return value == infinity and '1/0'
26 or value == -infinity and '-1/0'
24 or value ~= value and writeNan(value)
26 or ('%.17G'):format(value)
end
-- serialize strings
2 function writer.string (value)
24 return ('%q'):format(value)
end
-- serialize booleans
2 writer.boolean = tostring
-- concatenate array, joined by and terminated with line break
local function lines (t)
4 return #t == 0 and '' or tconcat(t, '\n') .. '\n'
end
-- generate serialized result
2 local write = getWriter(value)
2 local result = write and write(value) or 'nil'
2 return lines(intro) .. lines(outro) .. 'return ' .. result
end
==============================================================================
./knife/system.lua
==============================================================================
1 local loadstring = _G.loadstring or _G.load
1 local tconcat = table.concat
1 local type = type
local function hasSigil (sigil, value)
189 return type(value) == 'string' and sigil:byte() == value:byte()
end
return function (aspects, process)
17 local args = {}
17 local cond = {}
17 local results = {}
17 local localIndex = 0
17 local choicePattern = '([^|]+)'
local function suppress (aspect, condition)
2 cond[#cond + 1] = 'if nil'
4 for option in aspect:gmatch(choicePattern) do
2 cond[#cond + 1] = condition:format(option)
end
2 cond[#cond + 1] = 'then return end'
end
local function supply (aspect, isOptional, isReturned)
30 localIndex = localIndex + 1
30 cond[#cond + 1] = ('local l%d = nil'):format(localIndex)
62 for option in aspect:gmatch(choicePattern) do
32 cond[#cond + 1] = ('or _entity[%q]'):format(option)
end
30 if not isOptional then
29 cond[#cond + 1] = ('if not l%d then return end'):format(localIndex)
end
30 if isReturned then
1 results[#results + 1] = ('_entity[%q]'):format(aspect)
end
30 args[#args + 1] = ('l%d'):format(localIndex)
end
53 for index = 1, #aspects do
36 local aspect = aspects[index]
36 if hasSigil('_', aspect) then
4 args[#args + 1] = aspect
32 elseif hasSigil('!', aspect) or hasSigil('~', aspect) then
1 suppress(aspect:sub(2), 'or _entity[%q]')
31 elseif hasSigil('-', aspect) then
1 suppress(aspect:sub(2), 'or not _entity[%q]')
30 elseif hasSigil('?', aspect) then
1 supply(aspect:sub(2), true)
29 elseif hasSigil('=', aspect) then
1 supply(aspect:sub(2), false, true)
else
28 supply(aspect, false)
end
end
local source = ([[
local _aspects, _process = ...
return function (_entity, ...)
%s
%s _process(%s ...)
return true
34 end]]):format(
17 tconcat(cond, ' '),
17 results[1] and (tconcat(results, ',') .. ' = ') or '',
17 args[1] and (tconcat(args, ', ') .. ', ') or '')
17 return loadstring(source)(aspects, process)
end
==============================================================================
./knife/test.lua
==============================================================================
local test, testAssert, testError
-- Create a node representing a test section
local function createNode (parent, description, process)
190 return setmetatable({
95 parent = parent,
95 description = description,
95 process = process,
95 nodes = {},
95 activeNodeIndex = 1,
95 currentNodeIndex = 0,
95 assert = testAssert,
95 error = testError,
190 }, { __call = test })
end
-- Run a node
local function runNode (node)
230 node.currentNodeIndex = 0
230 return node:process()
end
-- Get the root node for a given node
local function getRootNode (node)
202 local parent = node.parent
202 return parent and getRootNode(parent) or node
end
-- Update the active child node of the given node
local function updateActiveNode (node, description, process)
135 local activeNodeIndex = node.activeNodeIndex
135 local nodes = node.nodes
135 local activeNode = nodes[activeNodeIndex]
135 if not activeNode then
82 activeNode = createNode(node, description, process)
82 nodes[activeNodeIndex] = activeNode
else
53 activeNode.process = process
end
135 getRootNode(node).lastActiveLeaf = activeNode
135 return activeNode
end
-- Run the active child node of the given node
local function runActiveNode (node, description, process)
135 local activeNode = updateActiveNode(node, description, process)
135 return runNode(activeNode)
end
-- Get ancestors of a node, including the node
local function getAncestors (node)
2 local ancestors = { node }
14 for ancestor in function () return node.parent end do
5 ancestors[#ancestors + 1] = ancestor
5 node = ancestor
end
2 return ancestors
end
-- Print a message describing one execution path in the test scenario
local function printScenario (node)
2 local ancestors = getAncestors(node)
9 for i = #ancestors, 1, -1 do
7 io.stderr:write(ancestors[i].description or '')
7 io.stderr:write('\n')
end
end
-- Print a message and stop the test scenario when an assertion fails
local function failAssert (node, description, message)
2 io.stderr:write(message or '')
2 io.stderr:write('\n\n')
2 printScenario(node)
2 io.stderr:write(description or '')
2 io.stderr:write('\n\n')
2 error(message or '', 2)
end
-- Create a branch node for a test scenario
test = function (node, description, process)
598 node.currentNodeIndex = node.currentNodeIndex + 1
598 if node.currentNodeIndex == node.activeNodeIndex then
135 return runActiveNode(node, description, process)
end
end
-- Test an assertion
testAssert = function (self, value, description)
245 if not value then
1 return failAssert(self, description, 'Test failed: assertion failed')
end
244 return value
end
-- Expect function f to fail
testError = function (self, f, description)
14 if pcall(f) then
1 return failAssert(self, description, 'Test failed: expected error')
end
end
-- Create the root node for a test scenario
local function T (description, process)
13 local root = createNode(nil, description, process)
13 runNode(root)
95 while root.activeNodeIndex <= #root.nodes do
82 local lastActiveBranch = root.lastActiveLeaf.parent
82 lastActiveBranch.activeNodeIndex = lastActiveBranch.activeNodeIndex + 1
82 runNode(root)
end
13 return root
end
-- Run any other files passed from CLI.
1 if arg and arg[0] and arg[0]:gmatch('test.lua') then
1 _G.T = T
12 for i = 1, #arg do
11 dofile(arg[i])
end
1 _G.T = nil
end
1 return T
==============================================================================
./knife/timer.lua
==============================================================================
1 local Timer = {}
-- group management
local function detach (group, item)
17 local index = item.index
17 group[index] = group[#group]
17 group[index].index = index
17 group[#group] = nil
17 item.groupField = nil
end
local function attach (group, item)
22 if item.groupField then
9 detach (item.groupField, item)
end
22 local index = #group + 1
22 item.index = index
22 group[index] = item
22 item.groupField = group
22 item.lastGroup = group
end
-- instance update methods
local function updateContinuous (self, dt)
3 local cutoff = self.cutoff
3 local elapsed = self.elapsed + dt
3 if self:callback(dt) == false or elapsed >= cutoff then
1 if self.finishField then
1 self:finishField(elapsed - cutoff)
end
1 self:remove()
end
3 self.elapsed = elapsed
3 return
end
local function updateIntermittent (self, dt)
6 local duration = self.delay or self.interval
6 local elapsed = self.elapsed + dt
9 while elapsed >= duration do
7 elapsed = elapsed - duration
7 if self.limitField then
4 self.limitField = self.limitField - 1
end
7 if self:callback(elapsed) == false
7 or self.delay or self.limitField == 0 then
4 if self.finishField then
1 self:finishField(elapsed)
end
4 self:remove()
4 return
end
end
2 self.elapsed = elapsed
end
local function updateTween (self, dt)
11 local elapsed = self.elapsed + dt
11 local plan = self.plan
11 local duration = self.duration
11 self.elapsed = elapsed
11 if elapsed >= duration then
3 for index = 1, #plan do
2 local task = plan[index]
2 task.target[task.key] = task.final
end
1 if self.finishField then
1 self:finishField(elapsed - duration)
end
1 self:remove()
1 return
end
10 local ease = self.easeField
30 for index = 1, #plan do
20 local task = plan[index]
20 local target, key = task.target, task.key
20 local initial, change = task.initial, task.change
20 target[key] = ease(elapsed, initial, change, duration)
end
end
-- shared instance methods
1 local defaultGroup = {}
local function group (self, group)
11 if not group then
2 group = defaultGroup
end
11 attach(group, self)
11 return self
end
local function remove (self)
8 if self.groupField then
8 detach(self.groupField, self)
end
8 return self
end
local function register (self)
1 attach(self.lastGroup, self)
1 return self
end
local function limit (self, limitField)
1 self.limitField = limitField
1 return self
end
local function finish (self, finishField)
6 self.finishField = finishField
6 return self
end
local function ease (self, easeField)
4 self.easeField = easeField
4 return self
end
-- tweening helper functions
local function planTween (definition)
5 local plan = {}
10 for target, values in pairs(definition) do
15 for key, final in pairs(values) do
10 local initial = target[key]
10 plan[#plan + 1] = {
10 target = target,
10 key = key,
10 initial = initial,
10 final = final,
10 change = final - initial,
10 }
end
end
5 return plan
end
local function easeLinear (elapsed, initial, change, duration)
2 return change * elapsed / duration + initial
end
-- instance initializer
local function initialize (timer)
10 timer.elapsed = 0
10 timer.group = group
10 timer.remove = remove
10 timer.register = register
10 attach(defaultGroup, timer)
10 return timer
end
-- static api
1 function Timer.after (delay, callback)
6 return initialize {
3 delay = delay,
3 callback = callback,
3 update = updateIntermittent,
}
end
1 function Timer.every (interval, callback)
2 return initialize {
1 interval = interval,
1 callback = callback,
1 update = updateIntermittent,
1 limit = limit,
1 finish = finish,
}
end
1 function Timer.prior (cutoff, callback)
2 return initialize {
1 cutoff = cutoff,
1 callback = callback,
1 update = updateContinuous,
1 finish = finish,
}
end
1 function Timer.tween (duration, definition)
10 return initialize {
5 duration = duration,
5 plan = planTween(definition),
5 update = updateTween,
5 easeField = easeLinear,
5 ease = ease,
5 finish = finish,
}
end
1 function Timer.update (dt, group)
25 if not group then
1 group = defaultGroup
end
45 for index = #group, 1, -1 do
20 group[index]:update(dt)
end
end
1 function Timer.clear (group)
1 if not group then
1 group = defaultGroup
end
2 for i = 1, #group do
1 group[i] = nil
end
end
1 Timer.defaultGroup = defaultGroup
1 return Timer
==============================================================================
./spec/base.lua
==============================================================================
local function checkSubSuper (T, Sub, Super)
52 T:assert(getmetatable(Sub).__index == Super,
26 'Then the super is the index for the sub')
52 T:assert(Sub ~= Super,
26 'Then the super is not identical to the sub')
end
local function checkNotCallable (T, instance)
24 T:error(function () instance() end,
8 'Then the instance is not callable')
end
local function checkConstruct (T, Class)
36 T('When instantiated with the default constructor',
function (T)
4 Class.constructor = nil
4 local c = Class()
4 checkSubSuper(T, c, Class)
4 checkNotCallable (T, c)
end)
36 T('When instantiated with a custom constructor',
function (T)
8 function Class:constructor (x) self.x = x; return x, 45 end
4 local c, x, y = Class(123)
8 T:assert(c.x == 123,
4 'Then the constructor is applied to the instance')
8 T:assert(x == 123 and y == 45,
4 'Then return values from the constructor follow the instance')
4 checkSubSuper(T, c, Class)
4 checkNotCallable (T, c)
end)
end
local function checkExtend (T, Class)
24 T('When a class is extended',
function (T)
6 local Sub = Class:extend()
6 checkSubSuper(T, Sub, Class)
6 checkConstruct(T, Sub)
end)
end
2 T('Given a base class',