Start typing to search packages!
limitedtable
By @glitchymosh
Roblox
MirroredLimitedTable
Constructor of Luau tables with size limits. Useful for interpreters, VMs and much more.
Installation
GitHub
Download the latest .rbxm file from releases and insert it into Roblox Studio.
Creator Marketplace
Wally
-
Add LimitedTable to dependencies in
wally.tomlinside your project:limitedtable = "glitchymosh/limitedtable@1.2.0" -
Update dependencies using shell:
wally install
Usage
Properties
.maximumSize
LimitedTable.maximumSize: number
Determines the maximum allowed size of data inside LimitedTable. This must be specified.
.table
LimitedTable.table: { [any]: any }
The real table with contents of LimitedTable (aka LimitedTableTable). Use only for getting values.
.sizeExceededMessage
LimitedTable.sizeExceededMessage: string | (table: LimitedTableTable) -> (),
Determines the error message that will be raised when the maximum size is exceeded. Alternatively, it can be a function that will be invoked instead of raising an error.
Default: maximum size of %s bytes exceeded
Functions
.new
function LimitedTable.new(
maximumSize: number,
errorMessage: (string | () -> ())?
): LimitedTable
Construct a new LimitedTable with given size limit of maximumSize bytes.
Writing a value that exceeds LimitedTable's size will raise an error with errorMessage. If the errorMessage is a function, then that function will be called instead.
Example:
local lt = LimitedTable.new(512000)
lt.maximumSize += 64000
lt.sizeExceededMessage = "bum"
lt.sizeExceededMessage = function()
game.Players.LocalPlayer:Kick()
end
isValid
function LimitedTable.isValid(
object: LimitedTable
): boolean
Checks if the given object is a valid LimitedTable from this module.
Example:
print(LimitedTable.isValid(LimitedTable.new(512000))) --> true
print(LimitedTable.isValid({})) --> false
isTable
function LimitedTable.isTable(
object: LimitedTableTable
): boolean
Checks if the given object is a valid LimitedTableTable from this module.
Example:
print(LimitedTable.isTable(LimitedTable.new(512000).table)) --> true
print(LimitedTable.isTable({})) --> false
getOwner
function LimitedTable.getOwner(
table: LimitedTableTable
): LimitedTable?
Returns the LimitedTable that the table belongs to, or nil if not found.
Example:
local lt = LimitedTable.new(512000)
print(LimitedTable.getOwner(lt.table) == lt) --> true
local another = LimitedTable.new(512000)
print(LimitedTable.getOwner(lt.table) == another) --> false
:set
function LimitedTable:set(
key: any,
value: any,
table: LimitedTableTable?,
apply: boolean?
): number
Sets key of given table to value and returns the size of the changes.
table defaults to LimitedTable.table. Optional parameter apply determines whether to apply given changes.
Example:
local lt = LimitedTable.new(512000)
lt:set("a", "hi")
lt:set("myArray", {})
lt:set(1, "lol", lt.table.myArray)
lt:set("myArray", {
"milk",
"eggs",
"cheese",
})
:insert
function LimitedTable:insert(
value: any,
array: LimitedTableTable?,
position: number?,
apply: boolean?
): number
Inserts value at given position of array and returns the size of the changes. If position is not provided, inserts to the end of the array.
array defaults to LimitedTable.table. Optional parameter apply determines whether to apply given changes.
Example:
local lt = LimitedTable.new(512000)
for i = 1, 10 do
lt:insert("Hello, world!")
end
lt:set("reversed", {})
for i = 10, 1, -1 do
lt:insert(i, lt.table.reversed, 1)
end
:remove
function LimitedTable:remove(
array: LimitedTableTable?,
position: number?,
apply: boolean?
): number
Removes element at given position from array and returns the size of the changes. If position is not provided, removes the last element from the array.
array defaults to LimitedTable.table. Optional parameter apply determines whether to apply given changes.
Example:
local lt = LimitedTable.new(512000)
lt:set("myArray", {
"milk",
"eggs",
"cheese",
})
lt:remove(lt.table.myArray) -- remove last element
lt:remove(lt.table.myArray, 1)
print(lt.table.myArray) --> { "eggs" }
:cloneRaw
function LimitedTable:cloneRaw(
table: LimitedTableTable?
): { [any]: any }
Returns a deep copy of table, with all LimitedTable tables replaced by normal ones.
table defaults to LimitedTable.table.
Example:
local lt = LimitedTable.new(512000)
lt:set("t", { 1, 2, 3 })
local raw = lt:cloneRaw(lt.table.t)
print(raw) --> { 1, 2, 3 }
print(raw == lt.table.t) --> false
:destroy
function LimitedTable:destroy(): ()
Destroys LimitedTable. Make sure to clear up all references!
Example:
local lt = LimitedTable.new(512000)
local references = setmetatable(
{ lt, lt.table },
{ __mode = "v" }
)
lt:destroy()
lt = nil
task.wait(5)
print(`deleted: {#references == 0}!`) --> true (unless something stupid happened)
Example
Check out the example usage of LimitedTable! Clone the Git repo and build the example project:
rojo build --output LimitedTableExample.rbxl example.project.json
Package Details
Install command (Click to copy)
Version
1.2.0
License
MIT
Safe for commercial use
Automated license review — not legal advice.
