Lua Sandbox Utility Module

1. Functions

1.1. behead_array

Effectively removes all array values up to the provided index from an array by copying end values to the array head and setting now unused entries at the end of the array to nil.

Arguments

  • index (number) - remove the values in the array up to the index value
  • array (table) - array to behead

Return

  • none - in-place operation

1.2. pairs_by_key

Sorts the keys into an array, and then iterates on the array.

Arguments

  • hash (table) - hash table to iterate in sorted key order
  • sort (function) - function to specify an alternate sort order

Return

  • function - iterator that traverses the table keys in sort function order

1.3. merge_objects

Merge two objects. Add all data from "src" to "dest". Numeric values are added, boolean and string values are overwritten, and arrays and objects are recursively merged. Any data with different types in dest and src will be skipped.

1.3.1. Example

local a = {
    foo = 1,
    bar = {1, 1, 3},
    quux = 3
}
local b = {
    foo = 5,
    bar = {0, 0, 5, 1},
    baz = {
        hello = 100
    }
}

local c = merge_objects(a, b)
-------
 c contains {
    foo = 6,
    bar = {1, 1, 8, 1},
    baz = {
        hello = 100
    },
    quux = 3
}

source code: util.lua

results matching ""

    No results matching ""