Localize globals per file for all modules

master
Lars Mueller 2021-06-11 20:47:29 +02:00
parent d8f3bf2902
commit 0315a77696
29 changed files with 87 additions and 1 deletions

View File

@ -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 metatable = {__index = function(_self, key)
return rawget(class, key)

View File

@ -1,3 +1,6 @@
-- Localize globals
local assert, math = assert, math
-- All little endian
--+ Reads doubles (f64) or floats (f32)

View File

@ -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
local bluon = getfenv(1)

View File

@ -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
function build_tree(dict)
local tree = {}

View File

@ -1,3 +1,6 @@
-- Localize globals
local _G, debug, getfenv, table, tostring = _G, debug, getfenv, table, tostring
function variables(stacklevel)
stacklevel = (stacklevel or 1) + 1
local locals = {}

View File

@ -1,3 +1,6 @@
-- Localize globals
local io, minetest, modlib, string = io, minetest, modlib, string
function read(filename)
local file = io.open(filename, "r")
if file == nil then return nil end

View File

@ -1,3 +1,6 @@
-- Localize globals
local error, modlib, unpack = error, modlib, unpack
no_op = function() end
function curry(func, ...)

View File

@ -1,3 +1,6 @@
-- Localize globals
local getfenv, math, setmetatable, table = getfenv, math, setmetatable, table
local metatable = {__index = getfenv(1)}
function less_than(a, b) return a < b end

View File

@ -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
if _VERSION then

View File

@ -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 metatable = {__index = function(_self, key)
return rawget(class, key)

View File

@ -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
minetest.mkdir(minetest.get_worldpath() .. "/logs")
channels = {}

View File

@ -1,3 +1,6 @@
-- Localize globals
local math, minetest, modlib, os, string, table = math, minetest, modlib, os, string, table
-- Make random random
math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock())
for _ = 1, 100 do math.random() end

View File

@ -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 {{...}}
local function get_collisionboxes(box_or_boxes)
return type(box_or_boxes[1]) == "number" and {box_or_boxes} or box_or_boxes

View File

@ -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
named_colors = {
aliceblue = 0xf0f8ff,

View File

@ -1,3 +1,6 @@
-- Localize globals
local minetest, modlib, pairs = minetest, modlib, pairs
liquid_level_max = 8
--+ Calculates the corner levels of a flowingliquid node
--> 4 corner levels from -0.5 to 0.5 as list of `modlib.vector`

View File

@ -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
function override(function_name, function_builder)
local func = minetest[function_name]

View File

@ -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
function raycast(_pos1, _pos2, objects, liquids)
local raycast = minetest.raycast(_pos1, _pos2, objects, liquids)

View File

@ -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 = {}
local metatable = {__index = schematic}

View File

@ -1,3 +1,6 @@
-- Localize globals
local minetest, modlib, pairs, table = minetest, modlib, pairs, table
players = {}
registered_on_wielditem_changes = {function(...)

View File

@ -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
function include(modname, file)
if not file then

View File

@ -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 = {}
local files = {}
local metatable = {__index = lua_log_file}

View File

@ -1,3 +1,6 @@
-- Localize globals
local ipairs, minetest, modlib = ipairs, minetest, modlib
forbidden_names = {}
function register_forbidden_name(name) forbidden_names[name] = true end

View File

@ -1,3 +1,6 @@
-- Localize globals
local math, modlib, pairs, unpack, vector = math, modlib, pairs, unpack, vector
-- TODO OOP, extend vector
function from_euler_rotation(rotation)

View File

@ -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 metatable = {__index = function(_self, key)
return rawget(class, key)

View File

@ -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 metatable = {__index = function(_self, key)
return rawget(class, key)

View File

@ -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
function map_index(table, func)

View File

@ -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 lower_first(text) return text:sub(1, 1):lower() .. text:sub(2) end

View File

@ -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 metatable = {__index = function(_self, key)
return rawget(class, key)

View File

@ -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 class = getfenv(1)