Created
August 31, 2014 04:22
-
-
Save balaam/ef60c5a4bafdc9d139ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| list = | |
| { | |
| {n="old", p=1} | |
| } | |
| function add(effect) | |
| for i = 1, #list do | |
| local priority = list[i].p | |
| if effect.p > priority then | |
| table.insert(list, i, effect) | |
| return | |
| end | |
| end | |
| table.insert(list, effect) | |
| end | |
| print("List before") | |
| for k, v in ipairs(list) do | |
| print(k, string.format("{n=%s, p=%d}", v.n, v.p)) | |
| end | |
| add({n="new", p=1}) | |
| print("List after") | |
| for k, v in ipairs(list) do | |
| print(k, string.format("{n=%s, p=%d}", v.n, v.p)) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment