mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Localize globals per file for all modules
This commit is contained in:
parent
d8f3bf2902
commit
0315a77696
3
b3d.lua
3
b3d.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, getfenv, math, modlib, next, pairs, rawget, setmetatable, table = assert, error, getfenv, math, modlib, next, pairs, rawget, setmetatable, table
|
||||||
|
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
local metatable = {__index = function(_self, key)
|
local metatable = {__index = function(_self, key)
|
||||||
return rawget(class, key)
|
return rawget(class, key)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, math = assert, math
|
||||||
|
|
||||||
-- All little endian
|
-- All little endian
|
||||||
|
|
||||||
--+ Reads doubles (f64) or floats (f32)
|
--+ Reads doubles (f64) or floats (f32)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, getfenv, ipairs, math, modlib, next, pairs, rawget, setmetatable, string, table, unpack = assert, error, getfenv, ipairs, math, modlib, next, pairs, rawget, setmetatable, string, table, unpack
|
||||||
|
|
||||||
--! experimental
|
--! experimental
|
||||||
local bluon = getfenv(1)
|
local bluon = getfenv(1)
|
||||||
|
|
||||||
|
3
conf.lua
3
conf.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type = assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type
|
||||||
|
|
||||||
-- not deprecated
|
-- not deprecated
|
||||||
function build_tree(dict)
|
function build_tree(dict)
|
||||||
local tree = {}
|
local tree = {}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local _G, debug, getfenv, table, tostring = _G, debug, getfenv, table, tostring
|
||||||
|
|
||||||
function variables(stacklevel)
|
function variables(stacklevel)
|
||||||
stacklevel = (stacklevel or 1) + 1
|
stacklevel = (stacklevel or 1) + 1
|
||||||
local locals = {}
|
local locals = {}
|
||||||
|
3
file.lua
3
file.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local io, minetest, modlib, string = io, minetest, modlib, string
|
||||||
|
|
||||||
function read(filename)
|
function read(filename)
|
||||||
local file = io.open(filename, "r")
|
local file = io.open(filename, "r")
|
||||||
if file == nil then return nil end
|
if file == nil then return nil end
|
||||||
|
3
func.lua
3
func.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local error, modlib, unpack = error, modlib, unpack
|
||||||
|
|
||||||
no_op = function() end
|
no_op = function() end
|
||||||
|
|
||||||
function curry(func, ...)
|
function curry(func, ...)
|
||||||
|
3
heap.lua
3
heap.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local getfenv, math, setmetatable, table = getfenv, math, setmetatable, table
|
||||||
|
|
||||||
local metatable = {__index = getfenv(1)}
|
local metatable = {__index = getfenv(1)}
|
||||||
|
|
||||||
function less_than(a, b) return a < b end
|
function less_than(a, b) return a < b end
|
||||||
|
4
init.lua
4
init.lua
@ -1,4 +1,6 @@
|
|||||||
local rawget, rawset = rawget, rawset
|
-- Localize globals
|
||||||
|
local _G, _VERSION, assert, debug, dump, error, load, loadfile, minetest, pairs, rawget, rawset, setmetatable, table, type = _G, _VERSION, assert, debug, dump, error, load, loadfile, minetest, pairs, rawget, rawset, setmetatable, table, type
|
||||||
|
|
||||||
|
|
||||||
-- Lua version check
|
-- Lua version check
|
||||||
if _VERSION then
|
if _VERSION then
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, getfenv, math, modlib, rawget, setmetatable, table, unpack = assert, getfenv, math, modlib, rawget, setmetatable, table, unpack
|
||||||
|
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
local metatable = {__index = function(_self, key)
|
local metatable = {__index = function(_self, key)
|
||||||
return rawget(class, key)
|
return rawget(class, key)
|
||||||
|
3
log.lua
3
log.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local ipairs, minetest, modlib, os, pairs, table = ipairs, minetest, modlib, os, pairs, table
|
||||||
|
|
||||||
-- Log helpers - write to log, force writing to file
|
-- Log helpers - write to log, force writing to file
|
||||||
minetest.mkdir(minetest.get_worldpath() .. "/logs")
|
minetest.mkdir(minetest.get_worldpath() .. "/logs")
|
||||||
channels = {}
|
channels = {}
|
||||||
|
3
math.lua
3
math.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local math, minetest, modlib, os, string, table = math, minetest, modlib, os, string, table
|
||||||
|
|
||||||
-- Make random random
|
-- Make random random
|
||||||
math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock())
|
math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock())
|
||||||
for _ = 1, 100 do math.random() end
|
for _ = 1, 100 do math.random() end
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, ipairs, math, minetest, pairs, table, type, vector = assert, ipairs, math, minetest, pairs, table, type, vector
|
||||||
|
|
||||||
-- Minetest allows shorthand collisionbox = {...} instead of {{...}}
|
-- Minetest allows shorthand collisionbox = {...} instead of {{...}}
|
||||||
local function get_collisionboxes(box_or_boxes)
|
local function get_collisionboxes(box_or_boxes)
|
||||||
return type(box_or_boxes[1]) == "number" and {box_or_boxes} or box_or_boxes
|
return type(box_or_boxes[1]) == "number" and {box_or_boxes} or box_or_boxes
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, math, minetest, setmetatable, tonumber, type = assert, error, math, minetest, setmetatable, tonumber, type
|
||||||
|
|
||||||
-- As in src/util/string.cpp
|
-- As in src/util/string.cpp
|
||||||
named_colors = {
|
named_colors = {
|
||||||
aliceblue = 0xf0f8ff,
|
aliceblue = 0xf0f8ff,
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local minetest, modlib, pairs = minetest, modlib, pairs
|
||||||
|
|
||||||
liquid_level_max = 8
|
liquid_level_max = 8
|
||||||
--+ Calculates the corner levels of a flowingliquid node
|
--+ Calculates the corner levels of a flowingliquid node
|
||||||
--> 4 corner levels from -0.5 to 0.5 as list of `modlib.vector`
|
--> 4 corner levels from -0.5 to 0.5 as list of `modlib.vector`
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, minetest, modlib, next, pairs, string, table, type = assert, minetest, modlib, next, pairs, string, table, type
|
||||||
|
|
||||||
max_wear = 2 ^ 16 - 1
|
max_wear = 2 ^ 16 - 1
|
||||||
function override(function_name, function_builder)
|
function override(function_name, function_builder)
|
||||||
local func = minetest[function_name]
|
local func = minetest[function_name]
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, math, minetest, modlib, pairs, setmetatable, vector = assert, math, minetest, modlib, pairs, setmetatable, vector
|
||||||
|
|
||||||
--+ Raycast wrapper with proper flowingliquid intersections
|
--+ Raycast wrapper with proper flowingliquid intersections
|
||||||
function raycast(_pos1, _pos2, objects, liquids)
|
function raycast(_pos1, _pos2, objects, liquids)
|
||||||
local raycast = minetest.raycast(_pos1, _pos2, objects, liquids)
|
local raycast = minetest.raycast(_pos1, _pos2, objects, liquids)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local VoxelArea, assert, error, io, ipairs, math, minetest, modlib, next, pairs, setmetatable, table, vector = VoxelArea, assert, error, io, ipairs, math, minetest, modlib, next, pairs, setmetatable, table, vector
|
||||||
|
|
||||||
schematic = {}
|
schematic = {}
|
||||||
local metatable = {__index = schematic}
|
local metatable = {__index = schematic}
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local minetest, modlib, pairs, table = minetest, modlib, pairs, table
|
||||||
|
|
||||||
players = {}
|
players = {}
|
||||||
|
|
||||||
registered_on_wielditem_changes = {function(...)
|
registered_on_wielditem_changes = {function(...)
|
||||||
|
3
mod.lua
3
mod.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local Settings, _G, assert, dofile, error, getmetatable, ipairs, loadfile, loadstring, minetest, modlib, pairs, rawget, rawset, setfenv, setmetatable, tonumber, type = Settings, _G, assert, dofile, error, getmetatable, ipairs, loadfile, loadstring, minetest, modlib, pairs, rawget, rawset, setfenv, setmetatable, tonumber, type
|
||||||
|
|
||||||
-- get resource + dofile
|
-- get resource + dofile
|
||||||
function include(modname, file)
|
function include(modname, file)
|
||||||
if not file then
|
if not file then
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, io, ipairs, loadfile, math, minetest, modlib, pairs, setfenv, setmetatable, type = assert, error, io, ipairs, loadfile, math, minetest, modlib, pairs, setfenv, setmetatable, type
|
||||||
|
|
||||||
lua_log_file = {}
|
lua_log_file = {}
|
||||||
local files = {}
|
local files = {}
|
||||||
local metatable = {__index = lua_log_file}
|
local metatable = {__index = lua_log_file}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local ipairs, minetest, modlib = ipairs, minetest, modlib
|
||||||
|
|
||||||
forbidden_names = {}
|
forbidden_names = {}
|
||||||
|
|
||||||
function register_forbidden_name(name) forbidden_names[name] = true end
|
function register_forbidden_name(name) forbidden_names[name] = true end
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local math, modlib, pairs, unpack, vector = math, modlib, pairs, unpack, vector
|
||||||
|
|
||||||
-- TODO OOP, extend vector
|
-- TODO OOP, extend vector
|
||||||
|
|
||||||
function from_euler_rotation(rotation)
|
function from_euler_rotation(rotation)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, getfenv, modlib, pairs, rawget, setmetatable, table = assert, getfenv, modlib, pairs, rawget, setmetatable, table
|
||||||
|
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
local metatable = {__index = function(_self, key)
|
local metatable = {__index = function(_self, key)
|
||||||
return rawget(class, key)
|
return rawget(class, key)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, getfenv, ipairs, math, minetest, modlib, pairs, rawget, setmetatable, table, tonumber, tostring, type = assert, error, getfenv, ipairs, math, minetest, modlib, pairs, rawget, setmetatable, table, tonumber, tostring, type
|
||||||
|
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
local metatable = {__index = function(_self, key)
|
local metatable = {__index = function(_self, key)
|
||||||
return rawget(class, key)
|
return rawget(class, key)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, error, ipairs, math, next, pairs, rawget, rawset, setmetatable, string, table, type = assert, error, ipairs, math, next, pairs, rawget, rawset, setmetatable, string, table, type
|
||||||
|
|
||||||
-- Table helpers
|
-- Table helpers
|
||||||
|
|
||||||
function map_index(table, func)
|
function map_index(table, func)
|
||||||
|
3
text.lua
3
text.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local math, modlib, pairs, setmetatable, string, table = math, modlib, pairs, setmetatable, string, table
|
||||||
|
|
||||||
function upper_first(text) return text:sub(1, 1):upper() .. text:sub(2) end
|
function upper_first(text) return text:sub(1, 1):upper() .. text:sub(2) end
|
||||||
|
|
||||||
function lower_first(text) return text:sub(1, 1):lower() .. text:sub(2) end
|
function lower_first(text) return text:sub(1, 1):lower() .. text:sub(2) end
|
||||||
|
3
trie.lua
3
trie.lua
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local getfenv, math, next, pairs, rawget, setmetatable, string, table, unpack = getfenv, math, next, pairs, rawget, setmetatable, string, table, unpack
|
||||||
|
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
local metatable = {__index = function(_self, key)
|
local metatable = {__index = function(_self, key)
|
||||||
return rawget(class, key)
|
return rawget(class, key)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- Localize globals
|
||||||
|
local assert, getfenv, math, modlib, pairs, rawget, rawset, setmetatable, unpack, vector = assert, getfenv, math, modlib, pairs, rawget, rawset, setmetatable, unpack, vector
|
||||||
|
|
||||||
local mt_vector = vector
|
local mt_vector = vector
|
||||||
local class = getfenv(1)
|
local class = getfenv(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user