From a5af4b6ecdc3e4432c4d015989e57f760effd8e9 Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sat, 22 Aug 2015 22:45:07 -0400 Subject: [PATCH] Index systems from the end like string.sub. --- tiny.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tiny.lua b/tiny.lua index 3f3986b..af49411 100644 --- a/tiny.lua +++ b/tiny.lua @@ -696,11 +696,17 @@ end --- Sets the index of a System in the World, and returns the old index. Changes -- the order in which they Systems processed, because lower indexed Systems are --- processed first. Returns the old system.index. +-- processed first. If 'index' < 0, then sets 'index' relative to the last index +-- in the World; -1 is the index of the last System, -2 is the second to last, +-- and so on. Returns the old system.index. function tiny.setSystemIndex(world, system, index) local oldIndex = system.index local systems = world.systems + if index < 0 then + index = tiny.getSystemCount(world) + 1 + index + end + tremove(systems, oldIndex) tinsert(systems, index, system)