-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.lua
52 lines (44 loc) · 1.42 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---A combination of extensions to the Lua standard libraries and other useful utilities for libraries I use.
---@module extensions
-- This initialization module is designed for use in the Luvit environment.
-- It *will* not work elsewhere, however you can still copy the individual
-- extensions from the `libs` directory and they should work.
-- Luvit uses Luajit 2.1, but `table.new` is not included in the stdlib by default
require('table.new')
local extensions = {}
extensions.meta = {}
extensions.math = require('math.lua')
extensions.string = require('string.lua')
extensions.table = require('table.lua')
extensions.coroutine = require('coroutine.lua')
extensions.base = require('base.lua')
local autoload = {
math = extensions.math,
string = extensions.string,
table = extensions.table,
coroutine = extensions.coroutine,
}
---Loads the standard library extensions into the global environment. This will
---**not** overwrite any user-defined functions.
---@usage local extensions = require 'extensions' ()
function extensions.load()
for name, ext in pairs(autoload) do
for k, v in pairs(ext) do
if _G[name][k] == nil then
_G[name][k] = v
end
end
end
-- Load the base extensions into the global environment
for k, v in pairs(extensions.base) do
if _G[k] == nil then
_G[k] = v
end
end
end
function extensions.meta:__call()
self.load()
return self
end
setmetatable(extensions, extensions.meta)
return extensions