What is it?
The sandboxed table system is a little something I designed for my game personally since I’ve found myself in excess need of a few extra methods in the
table table provided by Roblox. I make extensive use of this in my own game, but given the versatility it offers, I’ve decided to release it to the public. This was inspired by @TheGamer101’s custom enum system, so kudos to him for kind of getting this idea started! (Here’s my own rewrite of it, for those who want it: https://www.roblox.com/library/3966022155/Custom-Enum-System. At the time of writing, I find myself unable to track down the original.)
What does it have to offer?
Right now, the sandboxed table system offers these new methods:
boolean table.contains(table tbl, Variant obj)
true if the table contains
false if it does not. Searches via calling
table.indexOf(tbl, obj) and returns if the data is non-nil.
table.find is NOT identical to this, as
table.find only works on arrays, not lookups (tables)
Variant table.indexOf(table tbl, Variant obj)
A hybrid utility method that first attempts to find
table.find(tbl, obj). If table.find cannot locate the value, it searches via
table.keyOf (see below).
Variant table.keyOf(table tbl, Variant obj)
Returns the index of
obj if it is present in the table, or
nil if it is not in the table. This searches using
pairs, so it supports custom indices. If your table is structured like an array, use
table.find() which comes with Roblox’s new luau VM.
table table.skip(table tbl, int n)
n values in
tbl and returns a new table starting from
n + 1 to the end of the table. This only works on ordinal tables (arrays).
table table.take(table tbl, int n)
n values from the start of
tbl and returns a new table containing only those values. This only works on ordinal tables (arrays).
table table.skipAndTake(table tbl, int skip, int take)
An alias with ever-so-slightly better performance that merges a skip and take operation into one call (so rather than doing
table.take(table.skip(MyArray, 4), 2), you just do
table.skipAndTake(MyArray, 4, 2).
Variant table.random(table tbl)
Selects a random entry out of tbl using Roblox’s
Random class (rather than
math.random). This only works on ordinal tables (arrays).
table table.join(table tbl0, table tbl1)
Merges the contents of tbl0 and tbl1 in order. This only works on ordinal tables (arrays).
What do you think should be added or changed? Let me know! Let’s get this module up to its maximum potential.