mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 09:03:01 +00:00
Make weac.table* appear in API docs
This commit is contained in:
parent
48af3e3127
commit
da97890e0c
14 changed files with 73 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
---
|
||||||
|
-- @module worldeditadditions_core.table
|
||||||
|
|
||||||
|
|
||||||
-- 4. Supporting recursive structures.
|
-- 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
|
-- Lua doesn't exactly come with batteries included, so this is quite an
|
||||||
-- extensive collection of functions :P
|
-- extensive collection of functions :P
|
||||||
|
-- @namespace worldeditadditions_core.table
|
||||||
|
|
||||||
local wea_c = worldeditadditions_core
|
local wea_c = worldeditadditions_core
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
---
|
||||||
|
-- @module worldeditadditions_core.table
|
||||||
|
|
||||||
|
|
||||||
--- Creates a table that stores data in keys.
|
--- 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
|
-- @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.
|
-- @param list table The table of values to convert to keys.
|
||||||
-- @return table The table of (key => true) pairs.
|
-- @return table The table of (key => true) pairs.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
---
|
||||||
|
-- @module worldeditadditions_core.table
|
||||||
|
|
||||||
|
|
||||||
--- Shallow clones a table.
|
--- Shallow clones a table.
|
||||||
-- @source http://lua-users.org/wiki/CopyTable
|
-- @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 source table The source to take values from
|
||||||
-- @param target table The target to write values to
|
-- @param target table The target to write values to
|
||||||
local function table_apply(source, target)
|
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.
|
--- Looks to see whether a given table contains a given value.
|
||||||
-- @param tbl table The table to look in.
|
-- @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.
|
--- 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
|
-- 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.
|
-- 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")
|
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.
|
--- Returns only the last count items in a given numerical table-based list.
|
||||||
-- @param tbl table The table to fetch items from.
|
-- @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.
|
--- 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.
|
-- Ignores return values that are nil and doesn't insert them into the table.
|
||||||
-- @param tbl table The table to operate on.
|
-- @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 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 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.
|
-- @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
|
--- Returns the key value pairs in a table as a single string
|
||||||
-- @param tbl table input table
|
-- @param tbl table input table
|
||||||
-- @param sep string key value seperator
|
-- @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.
|
--- 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.
|
-- @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.
|
-- @returns table A new table containing the values of the given table appearing at most once.
|
||||||
local function table_unique(tbl)
|
local function table_unique(tbl)
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
|
---
|
||||||
|
-- @module worldeditadditions_core.table
|
||||||
|
|
||||||
--- Polyfill for unpack / table.unpack.
|
--- Polyfill for unpack / table.unpack.
|
||||||
-- Calls unpack when available, and looks for table.unpack if unpack() isn't
|
-- Calls unpack when available, and looks for table.unpack if unpack() isn't
|
||||||
-- found.
|
-- found.
|
||||||
-- This is needed because in Lua 5.1 it's the global unpack(), but in Lua 5.4
|
-- This is needed because in Lua 5.1 it's the global unpack(), but in Lua 5.4
|
||||||
-- it's moved to table.unpack().
|
-- 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)
|
local function table_unpack(tbl, offset, count)
|
||||||
---@diagnostic disable-next-line: deprecated
|
---@diagnostic disable-next-line: deprecated
|
||||||
if type(unpack) == "function" then
|
if type(unpack) == "function" then
|
||||||
|
|
Loading…
Reference in a new issue