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-05-19 02:03:45 +00:00
|
|
|
stable_sort = require_relative("stable_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"},
|
|
|
|
{"stable_sort", "sort"},
|
|
|
|
{"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-04-07 03:49:10 +00:00
|
|
|
--export oo
|
2020-05-19 02:03:45 +00:00
|
|
|
class = self.class
|
|
|
|
|
|
|
|
--export assert
|
|
|
|
assert = self.assert
|
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)
|
|
|
|
self.stable_sort:export()
|
2020-03-15 09:28:50 +00:00
|
|
|
|
2020-04-07 03:49:10 +00:00
|
|
|
--functional module also available separate from table
|
2020-05-19 02:03:45 +00:00
|
|
|
functional = self.functional
|
2020-04-07 03:49:10 +00:00
|
|
|
|
2020-05-02 09:59:02 +00:00
|
|
|
--export collections
|
2020-05-19 02:03:45 +00:00
|
|
|
sequence = self.sequence
|
|
|
|
set = self.set
|
2020-04-07 03:49:10 +00:00
|
|
|
|
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-04-07 03:49:10 +00:00
|
|
|
--export geom
|
2020-05-19 02:03:45 +00:00
|
|
|
vec2 = self.vec2
|
|
|
|
vec3 = self.vec3
|
|
|
|
intersect = self.intersect
|
2020-03-15 09:28:50 +00:00
|
|
|
|
2020-05-02 09:59:02 +00:00
|
|
|
--"misc" :)
|
2020-05-19 02:03:45 +00:00
|
|
|
unique_mapping = self.unique_mapping
|
|
|
|
state_machine = self.state_machine
|
|
|
|
async = self.async
|
|
|
|
manual_gc = self.manual_gc
|
2020-03-15 09:28:50 +00:00
|
|
|
|
|
|
|
--support both spellings
|
2020-05-19 02:03:45 +00:00
|
|
|
colour = self.colour
|
|
|
|
color = self.colour
|
2020-04-07 03:49:10 +00:00
|
|
|
|
|
|
|
--export top level module as well for ease of migration for code
|
2020-05-19 02:03:45 +00:00
|
|
|
batteries = self
|
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
|