A utility module for table operations in ComputerCraft providing common table manipulation functions like searching, counting, copying, and comparison operations. Features: Element existence checking with includes(), table size counting for any table type, deep recursive copying with nested table support, deep recursive equality comparison, and works with both array-like and associative tables.
Recommended: Install via installer (handles dependencies automatically):
This pattern downloads and runs libraries at runtime, automatically installing any that are missing:
-- Auto-install and require libraries
local libs = {"tables"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local tables = require(libDir .. "tables")
-- Use the library
-- (your code here)
Alternative: Direct download via wget:
This example shows how to download and use libraries with automatic installation:
-- Auto-install and require libraries
local libs = {"tables"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local tables = require(libDir .. "tables")
-- Use the library
local tables = require("tables")
local myTable = {1, 2, 3, nested = {a = 1}}
print(tables.includes(myTable, 2)) -- true
local copy = tables.recursiveCopy(myTable)
print(tables.recursiveEquals(myTable, copy)) -- true
tables.includes(table, object)Check if a table contains a specific value
table (table): The table to search inobject (any): The value to search fortables.count(table)Count the number of elements in a table (works with both arrays and associative tables)
table (table): The table to count elements intables.recursiveCopy(table)Create a deep copy of a table, recursively copying all nested tables
table (table): The table to copytables.recursiveEquals(t1, t2)Compare two tables for deep equality, recursively checking nested tables
t1 (table): The first table to comparet2 (table): The second table to compare