mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Ldoc compliant
This commit is contained in:
@@ -177,7 +177,7 @@ end
|
||||
|
||||
--- Get a color table with a hexadecimal string.
|
||||
-- Optionally provide the value for the alpha channel.
|
||||
-- @tparam string hex hexadecimal color string (#ffffff, not #fff)
|
||||
-- @tparam string string hex hexadecimal color (#ffffff, not #fff)
|
||||
-- @tparam[opt=1] float alpha the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]***
|
||||
-- @treturn a color table with RGB converted from Hex and with alpha
|
||||
function Color.from_hex(hex, alpha)
|
||||
|
||||
@@ -36,7 +36,7 @@ end
|
||||
|
||||
--- Print msg if specified var evaluates to false.
|
||||
-- @tparam Mixed var variable to evaluate
|
||||
-- @tparam[opt="missing value"] string msg message
|
||||
-- @tparam[opt="missing string value"] msg message
|
||||
function Game.fail_if_missing(var, msg)
|
||||
if not var then
|
||||
error(msg or "Missing value", 3)
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
-- luacheck: globals string (Allow mutating string)
|
||||
|
||||
--- Returns a copy of the string with any leading or trailing whitespace from the string removed.
|
||||
-- @tparam string s the string to remove leading or trailing whitespace from
|
||||
-- @tparam string string s the to remove leading or trailing whitespace from
|
||||
-- @treturn string a copy of the string without leading or trailing whitespace
|
||||
function string.trim(s)
|
||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
--- Tests if a string starts with a given substring.
|
||||
-- @tparam string s the string to check for the start substring
|
||||
-- @tparam string string s the to check for the start substring
|
||||
-- @tparam string start the substring to test for
|
||||
-- @treturn boolean true if the start substring was found in the string
|
||||
function string.starts_with(s, start)
|
||||
@@ -20,7 +20,7 @@ function string.starts_with(s, start)
|
||||
end
|
||||
|
||||
--- Tests if a string ends with a given substring.
|
||||
-- @tparam string s the string to check for the end substring
|
||||
-- @tparam string string s the to check for the end substring
|
||||
-- @tparam string ends the substring to test for
|
||||
-- @treturn boolean true if the end substring was found in the string
|
||||
function string.ends_with(s, ends)
|
||||
@@ -28,7 +28,7 @@ function string.ends_with(s, ends)
|
||||
end
|
||||
|
||||
--- Tests if a string contains a given substring.
|
||||
-- @tparam string s the string to check for the substring
|
||||
-- @tparam string string s the to check for the substring
|
||||
-- @tparam string contains the substring to test for
|
||||
-- @treturn boolean true if the substring was found in the string
|
||||
function string.contains(s, contains)
|
||||
@@ -36,7 +36,7 @@ function string.contains(s, contains)
|
||||
end
|
||||
|
||||
--- Tests whether a string is empty.
|
||||
-- @tparam string s the string to test
|
||||
-- @tparam string string s the to test
|
||||
-- @treturn boolean true if the string is empty
|
||||
function string.is_empty(s)
|
||||
return s == nil or s == ''
|
||||
@@ -45,9 +45,9 @@ end
|
||||
--- Splits a string into an array.
|
||||
-- *Note:* Empty split substrings are not included in the resulting table.
|
||||
-- <p>For example, `string.split("foo.bar...", ".", false)` results in the table `{"foo", "bar"}`.
|
||||
-- @tparam string s the string to split
|
||||
-- @tparam string string s the to split
|
||||
-- @tparam[opt="."] string sep the separator to use.
|
||||
-- @tparam[opt=false] boolean pattern whether to interpret the separator as a lua pattern or plaintext for the string split
|
||||
-- @tparam[opt=false] string boolean pattern whether to interpret the separator as a lua pattern or plaintext for the split
|
||||
-- @treturn {string,...} an array of strings
|
||||
function string.split(s, sep, pattern)
|
||||
sep = sep or "."
|
||||
@@ -76,7 +76,7 @@ end
|
||||
--- Returns a string as a hex format (also a string)
|
||||
-- @usage a = 'foo'
|
||||
-- string.to_hex(a) -- return '666f6f'
|
||||
-- @tparam string str the string to encode
|
||||
-- @tparam string string str the to encode
|
||||
-- @treturn string the hex format of the string
|
||||
function string.to_hex(str)
|
||||
if not is_type(str,'string') then return '' end
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
---table.map(a, function(v) return v * 10 end) --produces: { 10, 20, 30, 40, 50 }
|
||||
--- @usage a = {1, 2, 3, 4, 5}
|
||||
---table.map(a, function(v, k, x) return v * k + x end, 100) --produces { 101, 104, 109, 116, 125}
|
||||
-- @tparam table tbl the table to be mapped to the transform
|
||||
-- @tparam function func the function to transform values
|
||||
-- @tparam table table tbl the to be mapped to the transform
|
||||
-- @tparam function function func the to transform values
|
||||
-- @param[opt] ... additional arguments passed to the function
|
||||
-- @treturn table a new table containing the keys and mapped values
|
||||
function table.map(tbl, func, ...)
|
||||
@@ -30,8 +30,8 @@ end
|
||||
---table.filter(a, function(v) return v % 2 == 0 end) --produces: { 2, 4 }
|
||||
--- @usage a = {1, 2, 3, 4, 5}
|
||||
---table.filter(a, function(v, k, x) return k % 2 == 1 end) --produces: { 1, 3, 5 }
|
||||
-- @tparam table tbl the table to be filtered
|
||||
-- @tparam function func the function to filter values
|
||||
-- @tparam table table tbl the to be filtered
|
||||
-- @tparam function function func the to filter values
|
||||
-- @param[opt] ... additional arguments passed to the function
|
||||
-- @treturn table a new table containing the filtered key-value pairs
|
||||
function table.filter(tbl, func, ...)
|
||||
@@ -53,8 +53,8 @@ end
|
||||
---table.find(a, function(v) return v % 2 == 0 end) --produces: 2
|
||||
--- @usage a = {1, 2, 3, 4, 5}
|
||||
---table.find(a, function(v, k, x) return k % 2 == 1 end) --produces: 1
|
||||
-- @tparam table tbl the table to be searched
|
||||
-- @tparam function func the function to use to search for any matching element
|
||||
-- @tparam table table tbl the to be searched
|
||||
-- @tparam function any func the function to use to search for matching element
|
||||
-- @param[opt] ... additional arguments passed to the function
|
||||
-- @treturn ?|nil|Mixed the first found value, or nil if none was found
|
||||
function table.find(tbl, func, ...)
|
||||
@@ -68,7 +68,7 @@ end
|
||||
|
||||
--- Finds the first index at which the value appears in the table
|
||||
-- @usage table.index({'foo','bar','baz'},'bar') -- retuns 2,'bar'
|
||||
-- @tparam table tbl the table to search though
|
||||
-- @tparam table table tbl the to search though
|
||||
-- @param value the value you want the index of
|
||||
-- @treturn number the index that the value apeears at
|
||||
-- @return the value in that possition
|
||||
@@ -83,7 +83,7 @@ end
|
||||
|
||||
--- Returns a boolean on weather the table includes the value or not
|
||||
-- @usage table.includes({'foo','bar','baz'},'bar') -- retuns true
|
||||
-- @tparam table tbl the table to search though
|
||||
-- @tparam table table tbl the to search though
|
||||
-- @param value the value you want the index of
|
||||
-- @treturn boolean if the table includes the value
|
||||
function table.includes(tbl, value)
|
||||
@@ -100,8 +100,8 @@ end
|
||||
-- Passes the index as second argument to the function.
|
||||
-- @usage a= { 1, 2, 3, 4, 5} table.any(a, function(v) return v % 2 == 0 end) --produces: true
|
||||
-- @usage a = {1, 2, 3, 4, 5} table.any(a, function(v, k, x) return k % 2 == 1 end) --produces: true
|
||||
-- @tparam table tbl the table to be searched
|
||||
-- @tparam function func the function to use to search for any matching element
|
||||
-- @tparam table table tbl the to be searched
|
||||
-- @tparam function any func the function to use to search for matching element
|
||||
-- @param[opt] ... additional arguments passed to the function
|
||||
-- @treturn boolean true if an element was found, false if none was found
|
||||
function table.any(tbl, func, ...)
|
||||
@@ -114,8 +114,8 @@ end
|
||||
-- @usage
|
||||
-- a = {10, 20, 30, 40}
|
||||
-- table.each(a, function(v) game.print(v) end) --prints 10, 20, 30, 40, 50
|
||||
-- @tparam table tbl the table to be iterated
|
||||
-- @tparam function func the function to apply to elements
|
||||
-- @tparam table table tbl the to be iterated
|
||||
-- @tparam function function func the to apply to elements
|
||||
-- @param[opt] ... additional arguments passed to the function
|
||||
-- @treturn table the table where the given function has been applied to its elements
|
||||
function table.each(tbl, func, ...)
|
||||
@@ -250,7 +250,7 @@ end
|
||||
|
||||
--- Creates a deep copy of table without copying Factorio objects.
|
||||
-- @usage local copy = table.deepcopy[data.raw.["stone-furnace"]["stone-furnace"]] -- returns a copy of the stone furnace entity
|
||||
-- @tparam table object the table to copy
|
||||
-- @tparam table table object the to copy
|
||||
-- @treturn table a copy of the table
|
||||
function table.deepcopy(object)
|
||||
local lookup_table = {}
|
||||
@@ -294,7 +294,7 @@ local function sortFunc(x, y) --sorts tables with mixed index types.
|
||||
end
|
||||
|
||||
--- Returns a copy of all of the values in the table.
|
||||
-- @tparam table tbl the table to copy the keys from, or an empty table if tbl is nil
|
||||
-- @tparam table table tbl the to copy the keys from, or an empty table if tbl is nil
|
||||
-- @tparam[opt] boolean sorted whether to sort the keys (slower) or keep the random order from pairs()
|
||||
-- @tparam[opt] boolean as_string whether to try and parse the values as strings, or leave them as their existing type
|
||||
-- @treturn array an array with a copy of all the values in the table
|
||||
@@ -320,7 +320,7 @@ function table.values(tbl, sorted, as_string)
|
||||
end
|
||||
|
||||
--- Returns a copy of all of the keys in the table.
|
||||
-- @tparam table tbl the table to copy the keys from, or an empty table if tbl is nil
|
||||
-- @tparam table table tbl the to copy the keys from, or an empty table if tbl is nil
|
||||
-- @tparam[opt] boolean sorted whether to sort the keys (slower) or keep the random order from pairs()
|
||||
-- @tparam[opt] boolean as_string whether to try and parse the keys as strings, or leave them as their existing type
|
||||
-- @treturn array an array with a copy of all the keys in the table
|
||||
@@ -350,7 +350,7 @@ end
|
||||
--table.remove_keys(a, {1,3}) --returns {nil, 2, nil, 4}
|
||||
-- @usage local b = {k1 = 1, k2 = 'foo', old_key = 'bar'}
|
||||
--table.remove_keys(b, {'old_key'}) --returns {k1 = 1, k2 = 'foo'}
|
||||
-- @tparam table tbl the table to remove the keys from
|
||||
-- @tparam table table tbl the to remove the keys from
|
||||
-- @tparam {Mixed,...} keys an array of keys that exist in the given table
|
||||
-- @treturn table tbl without the specified keys
|
||||
function table.remove_keys(tbl, keys)
|
||||
@@ -391,7 +391,7 @@ end
|
||||
--table.invert(a) --returns {'foo' = k1, 'bar' = k2}
|
||||
-- @usage local b = {k1 = 'foo', k2 = 'bar', k3 = 'bar'}
|
||||
--table.invert(b) --returns {'foo' = k1, 'bar' = ?}
|
||||
-- @tparam table tbl the table to invert
|
||||
-- @tparam table table tbl the to invert
|
||||
-- @treturn table a new table with inverted mapping
|
||||
function table.invert(tbl)
|
||||
local inverted = {}
|
||||
@@ -410,7 +410,7 @@ table.size = table_size
|
||||
--- For all string or number values in an array map them to a key = true table
|
||||
-- @usage local a = {"v1", "v2"}
|
||||
-- table.array_to_dict_bool(a) -- return {["v1"] = true, ["v2"]= true}
|
||||
-- @tparam table tbl the table to convert
|
||||
-- @tparam table table tbl the to convert
|
||||
-- @treturn table the converted table
|
||||
function table.arr_to_bool(tbl)
|
||||
local newtbl = {}
|
||||
|
||||
Reference in New Issue
Block a user