Skip to content

Instantly share code, notes, and snippets.

@balaam
Created August 31, 2014 04:22
Show Gist options
  • Select an option

  • Save balaam/ef60c5a4bafdc9d139ca to your computer and use it in GitHub Desktop.

Select an option

Save balaam/ef60c5a4bafdc9d139ca to your computer and use it in GitHub Desktop.
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