From 6b536ca88a840c10c1b68823d22a69d2246245fc Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 30 Jan 2023 00:14:28 +0100 Subject: [PATCH] Add a Lua function to concat two tables --- OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs index e347c00bed..e8535e4172 100644 --- a/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs @@ -85,6 +85,20 @@ namespace OpenRA.Mods.Common.Scripting return t; } + [Desc("Concatenates two Lua tables into a single table.")] + public LuaTable Concat(LuaValue[] firstCollection, LuaValue[] secondCollection) + { + var t = Context.CreateTable(); + + foreach (var e in firstCollection) + t.Add(t.Count + 1, e); + + foreach (var e in secondCollection) + t.Add(t.Count + 1, e); + + return t; + } + [Desc("Returns a random value from a collection.")] public LuaValue Random(LuaValue[] collection) {