From 98d7e7fc8b0bb3a6ad1af7537f065f6c8a9e09dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sun, 20 Feb 2022 20:48:20 +0100 Subject: [PATCH] table.copy: Add example --- doc/environment.adoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/environment.adoc b/doc/environment.adoc index 28f25e5..f8ff0ec 100644 --- a/doc/environment.adoc +++ b/doc/environment.adoc @@ -111,6 +111,15 @@ Deepcopies the table `t` and all it's subtables - both keys and values. Non-tabl The `seen` table is a lookup for already copied tables, which are used as keys. The value is the copy. By providing `[table] = table` entries for certain tables, you can prevent them from being copied. +Example: Preservation of referential structure means the ``assert``ion in the following code will work: + +[source,lua] +---- +a = {}; b = {a, a}; c = table.copy(b); assert(c[1] == c[2]) +---- + +A different deep cloning implementation might clone `a` twice, leading to `c[1] ~= c[2]`. + ==== `table.insert_all(t, other)` Adds all the list entries of `other` to `t` (list part concatenation).