From 6470b0a72b42b0f0776b6b55632159f7f7f4c065 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 7 Dec 2024 22:38:09 +0700 Subject: [PATCH] impl compat.move for 5.1 vanilla lua --- ROADMAP.md | 2 +- evolved/compat.lua | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 6acf647..9c24eb7 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -18,7 +18,7 @@ - [ ] add batch vector operations - [ ] add inplace vector operations - [x] cache chunk lists in batch operations -- [ ] impl compat.move for 5.1 vanilla lua +- [x] impl compat.move for 5.1 vanilla lua - [x] add registry.batch_set - [x] rename include/exclude/execute to query_include/exclude/execute - [x] rename entities/components to chunk_entities/components diff --git a/evolved/compat.lua b/evolved/compat.lua index c8f19ea..06efa4d 100644 --- a/evolved/compat.lua +++ b/evolved/compat.lua @@ -10,7 +10,23 @@ compat.unpack = table.unpack or function(list, i, j) end compat.move = table.move or function(a1, f, e, t, a2) - error('compat.move is not implemented yet', 2) + if a2 == nil then + a2 = a1 + end + + if e < f then + return a2 + end + + local d = t - f + + if t > e or t <= f or a2 ~= a1 then + for i = f, e do a2[i + d] = a1[i] end + else + for i = e, f, -1 do a2[i + d] = a1[i] end + end + + return a2 end return compat