[READ-ONLY] Mirror of https://github.com/thoda-dev/du-nested-coroutines. A small script for DU to avoid any CPU load error
0

Configure Feed

Select the types of activity you want to include in your feed.

base version

Thomas (Jul 11, 2021, 1:22 PM +0200) f06c176a e64f23ec

+221
+5
.gitignore
··· 1 + .idea 2 + idea/* 3 + .idea/du-nested-coroutines.iml 4 + .idea/modules.xml 5 + .idea/vcs.xml
+5
.idea/.gitignore
··· 1 + # Default ignored files 2 + /shelf/ 3 + /workspace.xml 4 + # Editor-based HTTP Client requests 5 + /httpRequests/
+12
.idea/du-nested-coroutines.iml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <module type="WEB_MODULE" version="4"> 3 + <component name="NewModuleRootManager"> 4 + <content url="file://$MODULE_DIR$"> 5 + <excludeFolder url="file://$MODULE_DIR$/temp" /> 6 + <excludeFolder url="file://$MODULE_DIR$/.tmp" /> 7 + <excludeFolder url="file://$MODULE_DIR$/tmp" /> 8 + </content> 9 + <orderEntry type="inheritedJdk" /> 10 + <orderEntry type="sourceFolder" forTests="false" /> 11 + </component> 12 + </module>
+8
.idea/modules.xml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <project version="4"> 3 + <component name="ProjectModuleManager"> 4 + <modules> 5 + <module fileurl="file://$PROJECT_DIR$/.idea/du-nested-coroutines.iml" filepath="$PROJECT_DIR$/.idea/du-nested-coroutines.iml" /> 6 + </modules> 7 + </component> 8 + </project>
+6
.idea/vcs.xml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <project version="4"> 3 + <component name="VcsDirectoryMappings"> 4 + <mapping directory="$PROJECT_DIR$" vcs="Git" /> 5 + </component> 6 + </project>
+24
README.md
··· 1 1 # du-nested-coroutines 2 2 A small script for DU to avoid any CPU load error 3 + 4 + ### How to use 5 + Write your functions in the unit > start event, in the table `MyCoroutines`. 6 + 7 + You can use the stardard coroutine.yield method in your function by always placing as parameter the table `coroutinesTable[index]` replacing `index` with the index of your function (1 for the 1st function, 2 for the second and so on) 8 + 9 + #### example 10 + 11 + ```lua 12 + MyCoroutines = { 13 + function() 14 + for i=0, 10 do 15 + system.print("function 1 --- "..i) 16 + coroutine.yield(coroutinesTable[1])--start with index 1 and so on 17 + end 18 + end, 19 + function() 20 + for i=0, 10 do 21 + system.print("function 2 --- "..i) 22 + coroutine.yield(coroutinesTable[2])--the second fonction yiel is with index 2 23 + end 24 + end 25 + } 26 + ```
+117
Source/config.json
··· 1 + { 2 + "slots": { 3 + "0": { 4 + "name": "slot1", 5 + "type": { 6 + "events": [], 7 + "methods": [] 8 + } 9 + }, 10 + "1": { 11 + "name": "slot2", 12 + "type": { 13 + "events": [], 14 + "methods": [] 15 + } 16 + }, 17 + "2": { 18 + "name": "slot3", 19 + "type": { 20 + "events": [], 21 + "methods": [] 22 + } 23 + }, 24 + "3": { 25 + "name": "slot4", 26 + "type": { 27 + "events": [], 28 + "methods": [] 29 + } 30 + }, 31 + "4": { 32 + "name": "slot5", 33 + "type": { 34 + "events": [], 35 + "methods": [] 36 + } 37 + }, 38 + "5": { 39 + "name": "slot6", 40 + "type": { 41 + "events": [], 42 + "methods": [] 43 + } 44 + }, 45 + "6": { 46 + "name": "slot7", 47 + "type": { 48 + "events": [], 49 + "methods": [] 50 + } 51 + }, 52 + "7": { 53 + "name": "slot8", 54 + "type": { 55 + "events": [], 56 + "methods": [] 57 + } 58 + }, 59 + "8": { 60 + "name": "slot9", 61 + "type": { 62 + "events": [], 63 + "methods": [] 64 + } 65 + }, 66 + "9": { 67 + "name": "slot10", 68 + "type": { 69 + "events": [], 70 + "methods": [] 71 + } 72 + }, 73 + "-1": { 74 + "name": "unit", 75 + "type": { 76 + "events": [], 77 + "methods": [] 78 + } 79 + }, 80 + "-2": { 81 + "name": "system", 82 + "type": { 83 + "events": [], 84 + "methods": [] 85 + } 86 + }, 87 + "-3": { 88 + "name": "library", 89 + "type": { 90 + "events": [], 91 + "methods": [] 92 + } 93 + } 94 + }, 95 + "handlers": [ 96 + { 97 + "code": "coroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n for i=0, 10 do\n system.print(\"function 1 --- \"..i)\n coroutine.yield(coroutinesTable[1])--start with index 1 and so on\n end\n end,\n function()\n for i=0, 10 do\n system.print(\"function 2 --- \"..i)\n coroutine.yield(coroutinesTable[2])--the second fonction yiel is with index 2\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)", 98 + "filter": { 99 + "args": [], 100 + "signature": "start()", 101 + "slotKey": "-1" 102 + }, 103 + "key": "0" 104 + }, 105 + { 106 + "code": "if coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend", 107 + "filter": { 108 + "args": [], 109 + "signature": "update()", 110 + "slotKey": "-2" 111 + }, 112 + "key": "1" 113 + } 114 + ], 115 + "methods": [], 116 + "events": [] 117 + }
+38
Source/unit/start.lua
··· 1 + coroutinesTable = {} 2 + --all functions here will become a coroutine 3 + MyCoroutines = { 4 + function() 5 + for i=0, 10 do 6 + system.print("function 1 --- "..i) 7 + coroutine.yield(coroutinesTable[1])--start with index 1 and so on 8 + end 9 + end, 10 + function() 11 + for i=0, 10 do 12 + system.print("function 2 --- "..i) 13 + coroutine.yield(coroutinesTable[2])--the second fonction yiel is with index 2 14 + end 15 + end 16 + } 17 + 18 + function initCoroutines() 19 + for _,f in pairs(MyCoroutines) do 20 + local co = coroutine.create(f) 21 + table.insert(coroutinesTable, co) 22 + end 23 + end 24 + 25 + initCoroutines() 26 + 27 + runCoroutines = function() 28 + for i,co in ipairs(coroutinesTable) do 29 + if coroutine.status(co) == "dead" then 30 + coroutinesTable[i] = coroutine.create(MyCoroutines[i]) 31 + end 32 + if coroutine.status(co) == "suspended" then 33 + assert(coroutine.resume(co)) 34 + end 35 + end 36 + end 37 + 38 + MainCoroutine = coroutine.create(runCoroutines)
+6
Source/update/update.lua
··· 1 + if coroutine.status(MainCoroutine) == "dead" then 2 + MainCoroutine = coroutine.create(runCoroutines) 3 + end 4 + if coroutine.status(MainCoroutine) == "suspended" then 5 + assert(coroutine.resume(MainCoroutine)) 6 + end