2020-01-29 03:26:28 +00:00
|
|
|
--[[
|
2020-03-15 09:28:50 +00:00
|
|
|
batteries for lua
|
2020-01-29 03:26:28 +00:00
|
|
|
|
2020-05-02 09:59:02 +00:00
|
|
|
a collection of helpful code to get your project off the ground faster
|
2020-01-29 03:26:28 +00:00
|
|
|
]]
|
|
|
|
|
|
|
|
local path = ...
|
2020-03-15 09:28:50 +00:00
|
|
|
local function require_relative(p)
|
|
|
|
return require(table.concat({path, p}, "."))
|
|
|
|
end
|
|
|
|
|
2020-04-07 03:49:10 +00:00
|
|
|
--build the module
|
|
|
|
local _batteries = {
|
|
|
|
--
|
2020-05-19 02:03:45 +00:00
|
|
|
class = require_relative("class"),
|
2020-04-17 00:35:00 +00:00
|
|
|
--
|
2020-05-19 02:03:45 +00:00
|
|
|
assert = require_relative("assert"),
|
|
|
|
--extension libraries
|
|
|
|
mathx = require_relative("mathx"),
|
|
|
|
tablex = require_relative("tablex"),
|
|
|
|
stringx = require_relative("stringx"),
|
2020-04-07 03:49:10 +00:00
|
|
|
--sorting routines
|
2020-06-02 05:00:46 +00:00
|
|
|
sort = require_relative("sort"),
|
2020-04-07 03:49:10 +00:00
|
|
|
--
|
2020-05-19 02:03:45 +00:00
|
|
|
functional = require_relative("functional"),
|
2020-05-02 09:59:02 +00:00
|
|
|
--collections
|
2020-05-19 02:03:45 +00:00
|
|
|
sequence = require_relative("sequence"),
|
|
|
|
set = require_relative("set"),
|
2020-04-17 00:35:00 +00:00
|
|
|
--geom
|
2020-05-19 02:03:45 +00:00
|
|
|
vec2 = require_relative("vec2"),
|
|
|
|
vec3 = require_relative("vec3"),
|
|
|
|
intersect = require_relative("intersect"),
|
2020-04-07 03:49:10 +00:00
|
|
|
--
|
2020-05-19 02:03:45 +00:00
|
|
|
unique_mapping = require_relative("unique_mapping"),
|
|
|
|
state_machine = require_relative("state_machine"),
|
|
|
|
async = require_relative("async"),
|
|
|
|
manual_gc = require_relative("manual_gc"),
|
|
|
|
colour = require_relative("colour"),
|
2020-04-07 03:49:10 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 02:03:45 +00:00
|
|
|
--assign aliases
|
|
|
|
for _, alias in ipairs({
|
|
|
|
{"mathx", "math"},
|
|
|
|
{"tablex", "table"},
|
|
|
|
{"stringx", "string"},
|
2020-06-02 05:00:46 +00:00
|
|
|
{"sort", "stable_sort"},
|
2020-05-19 02:03:45 +00:00
|
|
|
{"colour", "color"},
|
|
|
|
}) do
|
|
|
|
_batteries[alias[2]] = _batteries[alias[1]]
|
|
|
|
end
|
|
|
|
|
2020-04-07 03:49:10 +00:00
|
|
|
--easy export globally if required
|
2020-05-19 02:03:45 +00:00
|
|
|
function _batteries:export()
|
2020-08-09 09:49:24 +00:00
|
|
|
--export all key strings globally, if doesn't always exist
|
|
|
|
for k, v in pairs(self) do
|
|
|
|
if not _G[k] then
|
|
|
|
_G[k] = v
|
|
|
|
end
|
|
|
|
end
|
2020-04-07 03:49:10 +00:00
|
|
|
|
|
|
|
--overlay tablex and functional and sort routines onto table
|
2020-05-19 02:03:45 +00:00
|
|
|
self.tablex.overlay(table, self.tablex)
|
|
|
|
--now we can use it through table directly
|
|
|
|
table.overlay(table, self.functional)
|
2020-06-02 05:00:46 +00:00
|
|
|
self.sort:export()
|
|
|
|
|
2020-05-19 02:03:45 +00:00
|
|
|
--overlay onto global math table
|
|
|
|
table.overlay(math, self.mathx)
|
2020-04-07 03:49:10 +00:00
|
|
|
|
2020-04-17 00:35:00 +00:00
|
|
|
--overlay onto string
|
2020-05-19 02:03:45 +00:00
|
|
|
table.overlay(string, self.stringx)
|
2020-04-17 00:35:00 +00:00
|
|
|
|
2020-11-10 09:48:40 +00:00
|
|
|
--overwrite assert wholesale (it's compatible)
|
|
|
|
assert = self.assert
|
|
|
|
|
2020-04-07 03:49:10 +00:00
|
|
|
return self
|
2020-03-15 09:28:50 +00:00
|
|
|
end
|
2020-02-01 08:30:36 +00:00
|
|
|
|
2020-04-07 03:49:10 +00:00
|
|
|
return _batteries
|