-
Notifications
You must be signed in to change notification settings - Fork 1
/
tabMachine.lua
4756 lines (3981 loc) · 123 KB
/
tabMachine.lua
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
--author cs
--email [email protected]
--
--https://github.com/ThinEureka/tabMachine
--created on July 11, 2019
local table = table
local table_insert = table.insert
local table_remove = table.remove
local table_unpack = table.unpack
local table_pack = table.pack
local table_concat = table.concat
local rawget = rawget
local rawset = rawset
local next = next
local pairs = pairs
local ipairs = ipairs
local assert = assert
local type = type
local setmetatable = setmetatable
local xpcall = xpcall
local select = select
local str_byte = string.byte
local str_len = string.len
local tabMachine = class("tabMachine")
local context = class("context")
tabMachine.context = context
-- local tabProfiler = require("tabMachine.tabProfiler")
tabMachine.event_context_stop = "context_stop"
tabMachine.event_context_enter = "context_enter"
tabMachine.event_context_resume = "context_resume"
tabMachine.event_context_suspend = "context_suspend"
tabMachine.event_proxy_attached = "proxy_attached"
tabMachine.labels = {
update = true,
updateInterval = true,
updateTimerMgr = true,
event = true,
catch = true,
iquit = true,
final = true,
}
tabMachine.labelLens = {
}
local lifeState = {
running = 10,
quitting = 20,
quittted = 30,
stopped = 40,
-- recycled = 50, --current not used
-- clear = 60, --current not used
}
tabMachine.lifeState = lifeState
g_t = {}
g_t.empty_event = {}
g_t.empty_touch = function(target, type) end
g_t.empty_frame = function(...) end
g_t.empty_fun = function(...) end
g_t.anyOutputVars = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12"}
g_t.updateTimerMgr_normal = 1
g_t.updateTimerMgr_fixed = 2
g_t.updateTimerMgr_late = 3
tabMachine.tabKeywords = {
--current not used
tm = true,
__scheduler = true,
p = true,
--current not used
__pp = true,
__tab = true,
__name = true,
-- __isRoot = true,
__lifeId = true,
__lifeState = true,
__enterCount = true,
--current not used
__isStopped = true,
__isQuitted = true,
__isQuitting = true,
__isLifeTimeRelationStopped = true,
__isUpdateTickNotifyStopped = true,
__isSubStopped = true,
__isFinalized = true,
__isDetached = true,
__isDisposed = true,
__isNotifyStopped = true,
__isProxyStopped = true,
__event = true,
__updateFun = true,
__updateInterval = true,
__updateTimerMgr = true,
__quitFun = true,
__finalFun = true,
__catchFun = true,
__eventEx = true,
__updateFunEx = true,
__updateIntervalEx = true,
__updateTimerMgrEx = true,
__quitFunEx = true,
__finalFunEx = true,
__catchFunEx = true,
__outputVars = true,
__outputValues = true,
__updateTimer = true,
__subContexts = true,
--__childOpId = true,
__headProxyInfo = true,
__mapHeadListener = true,
__headListenInfo = true,
__runMode = true,
__breakPoints = true,
__suspends = true,
_nickName = true,
__dynamics = true,
__needDispose = true,
_hasMsg = true,
__banRecycleOutputVars = true,
}
for label, _ in pairs(tabMachine.labels) do
local len = label:len()
if #tabMachine.labelLens == 0 then
table_insert(tabMachine.labelLens, len)
else
local index = 1
while index <= #tabMachine.labelLens do
local oldLen = tabMachine.labelLens[index]
if len == oldLen then
break
elseif len < oldLen then
table_insert(tabMachine.labelLens, index, len)
break
else
if index == #tabMachine.labelLens then
table_insert(tabMachine.labelLens, len)
else
index = index + 1
end
end
end
end
end
local tabMachine_pcall = nil
local __nextLifeId = 1
function g_nextLifeId()
return __nextLifeId
end
__arrayPool = {}
local __arrayPool = __arrayPool
__mapPool = {}
local __mapPool = __mapPool
__contextPool = {}
local __contextPool = __contextPool
__contextRecyclePool = {}
local __contextRecyclePool = __contextRecyclePool
__subContainerPool = {}
local __subContainerPool = __subContainerPool
__subContainerRecyclePool = {}
local __subContainerRecyclePool = __subContainerRecyclePool
__contextTreePool = {}
local __contextTreePool = __contextTreePool
__contextTreeRecyclePool = {}
local __contextTreeRecyclePool = __contextTreeRecyclePool
g_frameIndex = 1
local g_frameIndex = g_frameIndex
__bindTabPool = {}
local __bindTabPool = __bindTabPool
__outputVarsPool = {}
local __outputVarsPool = __outputVarsPool
local tabMachine_compileTab = nil
local __anyDebuggerEanbled = false
local context_pJoin = nil
local context_pSelect = nil
local context_addSubContext = nil
local context_removeSubContext = nil
local context_checkNext = nil
local context_update = nil
local context_installTab = nil
-- local context_prepareEnter = nil
local context_stopSub = nil
local context_stopSelf = nil
local context_stopTree = nil
local context_collectStopTree = nil
local context_stopLifeTimeRelation = nil
local context_stopUpdateTickNotify = nil
local context_createTickAndUpdateTimers = nil
local context_destroyTickAndUpdateTimers = nil
local context_stopSubs = nil
local context_finalize = nil
local context_detach = nil
-- local context_dispose = nil
local context_notifyStop = nil
local context_notifyLifeTimeEvent = nil
local context_addEnterCount = nil
local context_decEnterCount = nil
local context_throwException = nil
local context_addProxy = nil
local context_removeProxy = nil
local context_resumeStepSuspends = nil
local context_needToBreak = nil
local context_addSuspend = nil
local context_addBreakPass = nil
local context_removeBreakPass = nil
local context_getLifeId = nil
local context_getSub = nil
local context_getSubByLifeId = nil
local context_getContextByLifeId = nil
local context_hasAnySub = nil
local context_start = nil
local context_call = nil
local context_throw = nil
local context_join = nil
local context_select = nil
local context_registerLifeTimeListener = nil
local context_unregisterLifeTimeListener = nil
local context_tabProxy = nil
local context_hasSub = nil
local context_output = nil
local context_getOutputs = nil
local context_abort = nil
local context_stop = nil
local context_stopAllSubs = nil
local context_getDetailedPath = nil
local context_isStopped = nil
local context_isQuitted = nil
local context_isQuitting = nil
local context_downDistance = nil
local context_upDistance = nil
local context_notify = nil
local context_notifyAll = nil
local context_upwardNotify = nil
local context_upwardNotifyAll = nil
local context_forEachSub = nil
local context_getScheduler = nil
local context_setScheduler = nil
local context_setDynamics = nil
local context_getDebugger = nil
local context_setDebugger = nil
local context_setTabProfiler = nil
local context_setBreakPoint = nil
local context_deleteBreakPoint = nil
local context_deleteAllBreakPoints = nil
local context_runNormally = nil
local context_breakAtNextBreakPoint = nil
local context_breakAtNextSub = nil
local context_resumeSuspends = nil
local context_suspend = nil
local context_postpone = nil
local context_resume = nil
local context_hasSuspend = nil
local context_tabSuspend = nil
local context_hasInner = nil
local context_getInner = nil
local context_safeInner = nil
local context_meta_call = nil
local context_meta_len = nil
local context_meta_shr = nil
local context_meta_bor = nil
local context_meta_band = nil
local context_meta_concat = nil
local g_t_rebind = nil
----------------- util functions ---------------------
local function outputValues(env, outputVars, outputValues)
for i, var in ipairs(outputVars) do
if var ~= nil then
if outputValues == nil then
env[var] = nil
else
env[var] = outputValues[i]
end
end
end
end
local function createContext(tab, ...)
local c = table_remove(__contextPool)
if c == nil then
c = {}
-- c.__lifeState = lifeState.running
c.__lifeState = 10
else
-- c.__lifeState = lifeState.running
c.__lifeState = 10
-- c._isRecycled = false
end
local lifeId = __nextLifeId
c.__lifeId = lifeId
__nextLifeId = lifeId + 1
if tab == nil then
setmetatable(c, context)
else
if not tab.__hooked then
local file, line = g_t.getTabCodeLocation(tab)
printError("tab without precompilation is deprecated now ",
" file: ", file, " ", line, "\n", debug.traceback())
g_t.precompile(tab)
end
setmetatable(c, tab)
end
-- c.__enterCount = 0
-- c.__childOpId = 0
-- if g_t.stat then
-- g_aliveContextCount = g_aliveContextCount + 1
-- g_historyContextCount = g_historyContextCount + 1
-- end
return c
end
----------------- tabMachine -------------------------
local __curStackNum = 0
__nextSubCache = {}
local __nextSubCache = __nextSubCache
g_getCurStackNum = function()
return __curStackNum
end
__commonLabelCache = {}
local __commonLabelCache = __commonLabelCache
__backwardCacheTable = {}
local __backwardCacheTable = __backwardCacheTable
__contextStack = {}
local __contextStack = __contextStack
function tabMachine:ctor()
g_tm = self
self.__isRunning = false
self.__rootContext = nil
self.__outputs = nil
self.__tab = nil
self.__curContext = nil
self.__debugger = nil
-- self.__contextStack = {}
-- self.__curStackNum = 0
-- self.__nextSubCache = {}
-- self.__backwardCacheTable = {}
self.__commonLabelCache = __commonLabelCache
end
function tabMachine:addNextSubCache(sub, num)
__nextSubCache[sub] = sub .. 1
for i = 0, num - 1 do
__nextSubCache[sub .. i] = sub .. (i+1)
end
end
function tabMachine:addCommonLabels(sub, num)
local name
for i = -1, num do
if i == -1 then
name = sub
else
name = sub .. i
end
__commonLabelCache[name] = {
update = name .. "_update",
updateInterval = name .. "_updateInterval",
event = name .. "_event",
final = name .."_final",
catch = name .."_catch",
}
end
end
tabMachine_compileTab = function (tab)
local targetTab = tab
local nextSubCacheTable = nil
local backwardCacheTable = nil
while targetTab and not rawget(targetTab, "__isNextSubCached") do
if backwardCacheTable == nil then
backwardCacheTable = __backwardCacheTable
end
for tag, _ in pairs(targetTab) do
if not backwardCacheTable[tag] then
backwardCacheTable[tag] = true
local l = str_len(tag)
local splitPos = l
local num = nil
local power = 1
for i = l, 1, -1 do
local code = str_byte(tag, i)
-- '0' = 48, '9' = 57
if code < 48 or code > 57 then
splitPos = i
break
else
if num == nil then
num = 0
end
num = num + (code - 48) * power
power = power * 10
end
end
if num ~= nil then
local base = tag:sub(1, splitPos)
if base ~= nil then
if nextSubCacheTable == nil then
nextSubCacheTable = __nextSubCache
end
nextSubCacheTable[base ..(num - 1)] = tag
if num == 1 then
nextSubCacheTable[base] = tag
end
end
end
end
end
rawset(targetTab, "__isNextSubCached", true)
targetTab = targetTab.super
end
local commonLabelCache = nil
while tab ~= nil and not rawget(tab, "__isLabelCached") do
rawset(tab, "__isLabelCached", true)
if commonLabelCache == nil then
commonLabelCache = __commonLabelCache
end
for tag, _ in pairs(tab) do
local l = str_len(tag)
local splitPos = 1
for _, labelLen in ipairs(tabMachine.labelLens) do
splitPos = l - labelLen
if splitPos <= 1 then
break
end
-- '_' == 95
if str_byte(tag, splitPos) == 95 then
break
end
--make sure splitPos is also correct for last iteration
splitPos = 0
end
if splitPos > 1 then
local base = tag:sub(1, splitPos - 1)
local label = tag:sub(splitPos + 1, -1)
if tabMachine.labels[label] ~= nil then
local baseCache = commonLabelCache[base]
if baseCache == nil then
baseCache = {}
commonLabelCache[base] = baseCache
end
baseCache[label] = tag
end
end
end
tab = tab.super
end
end
function tabMachine:installTab(tab)
local subContext = createContext(tab)
assert(subContext ~= nil)
-- subContext.tm = self
subContext.p = nil
subContext.__name = "root"
-- subContext.__isRoot = true
self.__rootContext = subContext
self.__tab = tab
context_installTab(self.__rootContext, tab)
end
function tabMachine:setDebugger(debugger)
__anyDebuggerEanbled = true
self.__debugger = debugger
end
function tabMachine:getDebugger()
return self.__debugger
end
function tabMachine:getScheduler()
return self.__scheduler
end
function tabMachine:setScheduler(scheduler)
self.__scheduler = scheduler
if self.__rootContext then
self.__rootContext:setScheduler(scheduler)
end
end
function tabMachine:start(...)
local debugger = __anyDebuggerEanbled and self.__debugger or nil
if debugger then
debugger:onMachineStart(self)
end
if self.__tab == nil then
return
end
self.__isRunning = true
--enter
local context = self.__rootContext
if debugger then
context.__debugger = debugger
end
context.__scheduler = self.__scheduler
self.__rootContext:start("s1", ...)
end
function tabMachine:stop()
if self.__rootContext then
context_stop(self.__rootContext)
end
-- callback _onStopped is expected to be called
-- then the variables would be proerly set
end
function tabMachine:isRunning()
return self.__isRunning
end
function tabMachine:getOutputs()
if self.__outputs then
return table_unpack(self.__outputs)
end
return nil
end
function tabMachine:_setOutputs(outputValues)
self.__outValues = outputValues
end
function tabMachine:_onStopped()
self.__isRunning = false
self.__rootContext = nil
end
tabMachine.compileTab = tabMachine_compileTab
--inline optimization
-- function tabMachine:_createContext(...)
-- local context = table_remove(__contextPool)
-- if context ~= nil then
-- return context
-- end
-- return context.new(...)
-- end
local tabMachine_onUnCaughtException = nil
local tabMachine_addContextException = nil
local cocosTabMachine_prettyStr = nil
local function tabMachine_throwError(target, errorMsg, traceback)
local e = {}
e.errorMsg = errorMsg
e.luaStackTrace = traceback
e.isCustom = nil
local i = __curStackNum
local catched = false
local contextStack = __contextStack
while i > 0 do
local context = contextStack[i].context
if context == nil then
break
end
if not context_throwException(target, e) then
if e.errorTabStatcks == nil then
e.errorTabStatcks = {}
end
table_insert(e.errorTabStatcks, context:getDetailedPath())
else
catched = true
end
i = i - 1
local lastContext = context
while i > 0 do
local context = contextStack[i].context
if context == nil then
break
end
if context == lastContext.p or context == lastContext then
lastContext = context
i = i - 1
else
break
end
end
end
if not catched then
tabMachine_onUnCaughtException(e)
end
end
tabMachine_onUnCaughtException = function(e)
dump(e, "uncaught exception", 100, printError)
--上报
local eMsg = ""
local errorMsg = e.errorMsg or "no errorMsg"
-- local reportVals = self:getObject("report") and self:getObject("report"):getTreeMsg() or "no reportVals"
local reportVals = "no report"
local errorTabStatcks = e.errorTabStatcks and cocosTabMachine_prettyStr(e.errorTabStatcks or {}) or "no errorTabStatcks"
local luaStackTrace = e.luaStackTrace or "no luaStackTrace"
local strTop = "==== errorMsg ====\n"
eMsg = eMsg .. strTop .. errorMsg
strTop = "\n\n==== reportVals ====\n"
eMsg = eMsg .. strTop .. reportVals
strTop = "\n\n==== errorTabStatcks ====\n"
eMsg = eMsg .. strTop .. errorTabStatcks
strTop = "\n\n==== luaStackTrace ====\n"
eMsg = eMsg .. strTop .. luaStackTrace
if fabric then
fabric:getInstance():allSet(tostring(errorMsg), eMsg, errorTabStatcks)
end
if g_enableDumpTabSnapshotOnCaughtException then
if tabSnapshotLogger then
tabSnapshotLogger:getInstance():dumpTabSnapshot(tostring(errorMsg), eMsg, errorTabStatcks)
end
end
end
cocosTabMachine_prettyStr = function (arr)
local str = ""
for _,v in ipairs(arr or {}) do
str = str .. v .. "\n"
end
return str
end
local __perror
local __traceback
local function on_error(error)
__perror = error
__traceback = debug.traceback("", 2)
end
tabMachine_pcall = function (target, f, selfParam, ...)
local curContextInfo
local curStackNum = __curStackNum + 1
__curStackNum = curStackNum
local contextStack = __contextStack
if #contextStack < curStackNum then
curContextInfo = {}
curContextInfo.context = target
table_insert(contextStack, curContextInfo)
else
curContextInfo = contextStack[curStackNum]
curContextInfo.context = target
end
local stat, result = xpcall(f, on_error, selfParam, ...)
if stat then
__curStackNum = curStackNum -1
curContextInfo.context = nil
return result
else
tabMachine_throwError(target, __perror, __traceback)
__curStackNum = curStackNum -1
curContextInfo.context = nil
end
--inline optimization
-- return nil
end
function tabMachine:_addContextException(e, context)
end
function tabMachine:_onUnCaughtException(e)
-- the subclass can override this function to
-- provide default handling of e
end
function tabMachine:_disposeContext(context)
-- the subclass may need to do some disposing work
end
---------------------- context -------------------------
local runMode = {
breakAtNextBreakPoint = 1,
breakAtNextSub = 2,
}
local context_name_stack = {}
local path_concat_table = {}
local function table_array_clear(t)
local n = #t
for i = 1, n do
t[i] = nil
end
end
local pathInversionTreeCache = {}
local function findPathInInversionTree(ctx)
local node = pathInversionTreeCache
local c = ctx
while c do
local childNode = node[c.__name]
if not childNode then
return nil
end
node = childNode
c = c.p
end
assert(type(node.__PATH__) == "string")
return node.__PATH__
end
local function RegisterToInversionTree(ctx, path)
local node = pathInversionTreeCache
local c = ctx
while c do
local name = c.__name
local childNode = node[c.__name]
if not childNode then
childNode = {}
node[name] = childNode
end
node = childNode
c = c.p
end
node.__PATH__ = path
node = path
end
local function generateContextPath(ctx)
table_array_clear(context_name_stack)
local index = 1
local c = ctx
while c do
context_name_stack[index] = c.__name
index = index + 1
c = c.p
end
table_array_clear(path_concat_table)
index = 1
for i = #context_name_stack, 1, -1 do
if index > 1 then
path_concat_table[index] = "."
path_concat_table[index + 1] = context_name_stack[i]
index = index + 2
else
path_concat_table[index] = context_name_stack[i]
index = index + 1
end
end
return table_concat(path_concat_table)
end
function context:_getPath()
local path = self.__path
if path then
return path
end
local path = findPathInInversionTree(self)
if not path then
path = generateContextPath(self)
end
self.__path = path
RegisterToInversionTree(self, path)
return path
end
context.getPath = context._getPath
context_getLifeId = function(self)
return self.__lifeId
end
context_getSub = function (self, scName)
local subContexts = self.__subContexts
if subContexts == nil then
return
end
for i = #subContexts, 1, -1 do
local subContext = subContexts[i]
if subContext.__name == scName then
return subContext
end
end
return nil
end
context_getSubByLifeId = function (self, lifeId)
local subContexts = self.__subContexts
if subContexts == nil then
return
end
for i = #subContexts, 1, -1 do
local subContext = subContexts[i]
if subContext.__lifeId == lifeId then
return subContext
end
end
return nil
end
context_getContextByLifeId = function (self, lifeId)
local contextArray = table_remove(__arrayPool)
if contextArray == nil then
contextArray = {}
end
table_insert(contextArray, self)
local index = 1
local target = nil
while index <= #contextArray do
target = contextArray[index]
if target.__lifeId == lifeId then
break
end
local subContexts = target.__subContexts
if subContexts ~= nil then
for i = #subContexts, 1, -1 do
local subContext = subContexts[i]
table_insert(contextArray, subContext)
end
end
target = nil
index = index + 1
end
while next(contextArray) do
table_remove(contextArray)
end
table_insert(__arrayPool, contextArray)
return target
end
context_hasAnySub = function (self)
local subContexts = self.__subContexts
return subContexts ~= nil and next(subContexts)
end
context_start = function (self, scName, ...)
-- if self.__lifeState >= lifeState.quitting then
if self.__lifeState >= 20 then
return
end
local selfTab = self.__tab
if selfTab == nil then
return
end
if self.__runMode ~= nil and context_needToBreak(self, scName) then
local params = table_pack(...)
local function resumeFun (resume, ...)
local resumeParamsNum = select("#", ...)
if resumeParamsNum <= 0 then
context_start(self, scName, table_unpack(params))
else
if params.n == 0 then
context_start(self, scName, ...)
else
context_start(self, scName, ...)
printError("invald pramas for resume")
end
end
end
context_addSuspend(self, resumeFun, scName)
return
end
-- self.__pc = self
-- self.__pcName = "self"
-- self.__pcAction = scName
--inline optimization
-- self:_addEnterCount()
local sub = selfTab[scName]
if sub == nil then
return
end
local enterCount = self.__enterCount
if enterCount then