mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-04 13:03:59 +01:00
Make weac.table* appear in API docs
This commit is contained in:
parent
48af3e3127
commit
da97890e0c
@ -1,3 +1,5 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
|
||||
-- 4. Supporting recursive structures.
|
||||
|
@ -4,9 +4,10 @@
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ██ ██████ ███████ ███████ ███████
|
||||
|
||||
-- Functions that operate on tables.
|
||||
--- Functions that operate on tables.
|
||||
-- Lua doesn't exactly come with batteries included, so this is quite an
|
||||
-- extensive collection of functions :P
|
||||
-- @namespace worldeditadditions_core.table
|
||||
|
||||
local wea_c = worldeditadditions_core
|
||||
|
||||
|
@ -1,4 +1,9 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
|
||||
--- Creates a table that stores data in keys.
|
||||
-- See also `worldeditadditions_core.Set`.
|
||||
-- @source https://riptutorial.com/lua/example/13407/search-for-an-item-in-a-list
|
||||
-- @param list table The table of values to convert to keys.
|
||||
-- @return table The table of (key => true) pairs.
|
||||
|
@ -1,3 +1,6 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
|
||||
--- Shallow clones a table.
|
||||
-- @source http://lua-users.org/wiki/CopyTable
|
||||
|
@ -1,5 +1,8 @@
|
||||
--- SHALLOW ONLY - applies the values in source to overwrite the equivalent keys in target.
|
||||
-- Warning: This function mutates target!
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- SHALLOW ONLY - applies the values in source to overwrite the equivalent keys in `target`.
|
||||
-- Warning: This function mutates `target`!
|
||||
-- @param source table The source to take values from
|
||||
-- @param target table The target to write values to
|
||||
local function table_apply(source, target)
|
||||
|
@ -1,3 +1,5 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Looks to see whether a given table contains a given value.
|
||||
-- @param tbl table The table to look in.
|
||||
|
@ -1,3 +1,6 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Filters the items in the given table using the given function.
|
||||
-- The function is executed for each item in the list. If it returns true, the
|
||||
-- item is kept. If it returns false, the item is discarded.
|
||||
|
26
worldeditadditions_core/utils/table/table_find.lua
Normal file
26
worldeditadditions_core/utils/table/table_find.lua
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Finds the first element in the given table that satisfies the given testing function.
|
||||
-- A port of Javascript's `array.find` to Lua.
|
||||
--
|
||||
-- Uses for .. in ipairs() under-the-hood.
|
||||
--
|
||||
-- @param tbl table The table to search.
|
||||
-- @param func function The testing function to call on each element. The function should return true/false as to whether the passed value passes the test function. The testing function will be provided with the following arguments:
|
||||
-- 1. `value` (any): The value being inspected.
|
||||
-- 2. `i` (number): The index in the table that the value can be found at
|
||||
-- 3. `tbl` (table): The original table.
|
||||
-- @return any|nil The first element in the table that satisfies the predicate, or nil if no such element is found.
|
||||
function table_find(tbl, func)
|
||||
end
|
||||
|
||||
function table_find(tbl, func)
|
||||
for i,value in ipairs(tbl) do
|
||||
if func(value, i, tbl) then
|
||||
return value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return table_find
|
@ -2,6 +2,8 @@ local wea_c = worldeditadditions_core
|
||||
|
||||
local table_unpack = dofile(wea_c.modpath.."/utils/table/table_unpack.lua")
|
||||
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Returns only the last count items in a given numerical table-based list.
|
||||
-- @param tbl table The table to fetch items from.
|
||||
|
@ -1,3 +1,6 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Executes the given function on every item in the given table.
|
||||
-- Ignores return values that are nil and doesn't insert them into the table.
|
||||
-- @param tbl table The table to operate on.
|
||||
|
@ -1,6 +1,7 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
|
||||
--- Lua implementation of array.reduce() from Javascript.
|
||||
--- Lua implementation of `array.reduce()` from Javascript.
|
||||
-- @param tbl The table to iterate over.
|
||||
-- @param func The function to call for every element in tbl. Will be passed the following arguments: accumulator, value, index, table. Of course, the provided function need not take this many arguments.
|
||||
-- @param initial_value The initial value of the accumulator.
|
||||
|
@ -1,3 +1,6 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Returns the key value pairs in a table as a single string
|
||||
-- @param tbl table input table
|
||||
-- @param sep string key value seperator
|
||||
|
@ -1,4 +1,9 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
|
||||
--- Builds a new table with the elements of the given table appearing at most once.
|
||||
-- See also `worldeditadditions_core.Set`.
|
||||
-- @param tbl table The table of values to make unique.
|
||||
-- @returns table A new table containing the values of the given table appearing at most once.
|
||||
local function table_unique(tbl)
|
||||
|
@ -1,8 +1,17 @@
|
||||
---
|
||||
-- @module worldeditadditions_core.table
|
||||
|
||||
--- Polyfill for unpack / table.unpack.
|
||||
-- Calls unpack when available, and looks for table.unpack if unpack() isn't
|
||||
-- found.
|
||||
-- This is needed because in Lua 5.1 it's the global unpack(), but in Lua 5.4
|
||||
-- it's moved to table.unpack().
|
||||
--
|
||||
-- Important: All unpack calls in WorldEditAdditions **MUST** use this function.
|
||||
-- @param tbl table The table to unpack
|
||||
-- @param [offset=0] number The offset at which to start unpacking.
|
||||
-- @param [count=nil] number The number of items to unpack. Defaults to unpack all remaining items after `offset`.
|
||||
-- @returns any... The selected items unpacked from the table.
|
||||
local function table_unpack(tbl, offset, count)
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
if type(unpack) == "function" then
|
||||
|
Loading…
Reference in New Issue
Block a user