diff --git a/b3d.lua b/b3d.lua index 9a27467..4ccb8bc 100644 --- a/b3d.lua +++ b/b3d.lua @@ -1,10 +1,11 @@ -- Localize globals -local assert, error, getfenv, math, modlib, next, pairs, rawget, setmetatable, table = assert, error, getfenv, math, modlib, next, pairs, rawget, setmetatable, table +local assert, error, math, modlib, next, pairs, setmetatable, table = assert, error, math, modlib, next, pairs, setmetatable, table -local class = getfenv(1) -local metatable = {__index = function(_self, key) - return rawget(class, key) -end} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} --! experimental --+ Reads a single BB3D chunk from a stream @@ -363,4 +364,7 @@ function get_animated_bone_properties(self, keyframe, interpolate) end get_props(self.node) return bone_properties -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/binary.lua b/binary.lua index a7e4b2a..79d58cb 100644 --- a/binary.lua +++ b/binary.lua @@ -1,6 +1,10 @@ -- Localize globals local assert, math = assert, math +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- All little endian --+ Reads doubles (f64) or floats (f32) @@ -115,4 +119,7 @@ end function write_double(write_byte, number) return write_float(write_byte, number, nil, true) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/bluon.lua b/bluon.lua index 9a8787f..20af1b6 100644 --- a/bluon.lua +++ b/bluon.lua @@ -1,15 +1,16 @@ -- 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 +local assert, error, ipairs, math, modlib, next, pairs, setmetatable, string, table, type, unpack = assert, error, ipairs, math, modlib, next, pairs, setmetatable, string, table, type, unpack + +-- Set environment +local _ENV = {} +setfenv(1, _ENV) --! experimental -local bluon = getfenv(1) local no_op = modlib.func.no_op local write_float = modlib.binary.write_float -local metatable = {__index = function(_self, key) - return rawget(bluon, key) -end} +local metatable = {__index = _ENV} function new(self) return setmetatable(self or {}, metatable) @@ -326,4 +327,7 @@ function read(self, stream) return end return _read(type) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/conf.lua b/conf.lua index 67e9035..8c4bd7c 100644 --- a/conf.lua +++ b/conf.lua @@ -1,6 +1,10 @@ -- 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 +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- not deprecated function build_tree(dict) local tree = {} @@ -296,4 +300,7 @@ function check_constraints(value, constraints) error(possible_errors) end end -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/debug.lua b/debug.lua index 51ffe7f..8d9998a 100644 --- a/debug.lua +++ b/debug.lua @@ -1,6 +1,10 @@ -- Localize globals local _G, debug, getfenv, table, tostring = _G, debug, getfenv, table, tostring +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + function variables(stacklevel) stacklevel = (stacklevel or 1) + 1 local locals = {} @@ -43,4 +47,7 @@ function stack(stacklevel) stacklevel = stacklevel + 1 end return stack -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/file.lua b/file.lua index 24441d6..4cf6db8 100644 --- a/file.lua +++ b/file.lua @@ -1,6 +1,10 @@ -- Localize globals local io, minetest, modlib, string = io, minetest, modlib, string +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + function read(filename) local file = io.open(filename, "r") if file == nil then return nil end @@ -107,4 +111,7 @@ end function process_bridge_start(name, command, os_execute) local bridge = process_bridges[name] os_execute(string.format(command, bridge.output, bridge.input, bridge.logs)) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/func.lua b/func.lua index 0892789..c1f1883 100644 --- a/func.lua +++ b/func.lua @@ -1,6 +1,10 @@ -- Localize globals local error, modlib, unpack = error, modlib, unpack +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + no_op = function() end function curry(func, ...) @@ -113,4 +117,7 @@ end function or_(a, b) return a or b -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/heap.lua b/heap.lua index b66b34e..c4a8c15 100644 --- a/heap.lua +++ b/heap.lua @@ -1,7 +1,11 @@ -- Localize globals -local getfenv, math, setmetatable, table = getfenv, math, setmetatable, table +local math, setmetatable, table = math, setmetatable, table -local metatable = {__index = getfenv(1)} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} function less_than(a, b) return a < b end @@ -50,4 +54,7 @@ function pop(self) end heapify(1) return value -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/init.lua b/init.lua index 17c1219..bc22ed8 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,5 @@ -- 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 - +local _G, _VERSION, assert, debug, dump, error, load, loadfile, minetest, pairs, rawget, rawset, setmetatable, table = _G, _VERSION, assert, debug, dump, error, load, loadfile, minetest, pairs, rawget, rawset, setmetatable, table -- Lua version check if _VERSION then @@ -58,33 +57,40 @@ for _, file in pairs{ "persistence", "debug" } do - modules[file] = file + modules[file] = true end if minetest then - modules.minetest = { - "misc", - "collisionboxes", - "liquid", - "raycast", - "wielditem_change", - "colorspec", - "schematic" - } for _, file in pairs{ + "minetest", "log", "player", -- deprecated "conf" } do - modules[file] = file + modules[file] = true end end -local load_module, get_resource, loadfile_exports +local parent_dir +if not minetest then + local init_path = arg and arg[0] + parent_dir = init_path and init_path:match"^.[/\\]" or "" +end + +-- only used if Minetest is available +local function get_resource(modname, resource, ...) + if not resource then + resource = modname + modname = minetest.get_current_modname() + end + return table.concat({minetest.get_modpath(modname), resource, ...}, modlib.dir_delim) +end + modlib = setmetatable({ -- TODO bump on release version = 69, modname = minetest and minetest.get_current_modname(), + -- TODO dir_delim = rawget(_G, "DIR_DELIM") or "/", _RG = setmetatable({}, { __index = function(_, index) @@ -101,55 +107,19 @@ modlib = setmetatable({ end }, { __index = function(self, module_name) - local files = modules[module_name] - local environment - if type(files) == "string" then - environment = load_module(files) - elseif files then - environment = loadfile_exports(get_resource(self.modname, module_name, files[1] .. ".lua")) - for index = 2, #files do - self.mod.include_env(get_resource(self.modname, module_name, files[index] .. ".lua"), environment) - end - else + if not modules[module_name] then + -- module not available, return nil return end - local module = {} - for key, value in pairs(environment) do - -- Shallow copy. Doesn't use `modlib.table.shallowcopy` as that is part of a module, too. - module[key] = value - end - self[module_name] = module - return module + local environment = dofile(minetest + and get_resource(self.modname, module_name .. ".lua") + or (parent_dir .. module_name .. ".lua")) + self[module_name] = environment + return environment end }) -function get_resource(modname, resource, ...) - if not resource then - resource = modname - modname = minetest.get_current_modname() - end - return table.concat({minetest.get_modpath(modname), resource, ...}, modlib.dir_delim) -end - -function loadfile_exports(filename) - local env = setmetatable({}, {__index = _G}) - local file = assert(loadfile(filename)) - setfenv(file, env) - file() - return env -end - -local parent_dir -if not minetest then - local init_path = arg and arg[0] - parent_dir = init_path and init_path:match"^.[/\\]" or "" -end -function load_module(module_name) - local file = module_name .. ".lua" - return loadfile_exports(minetest and get_resource(modlib.modname, file) or (parent_dir .. file)) -end - -modlib.mod = minetest and loadfile_exports(get_resource(modlib.modname, "mod.lua")) +modlib.mod = minetest and dofile(get_resource(modlib.modname, "mod.lua")) -- Aliases modlib.string = modlib.text @@ -157,15 +127,15 @@ modlib.number = modlib.math if minetest then modlib.conf.build_setting_tree() - modlib.mod.get_resource = get_resource - modlib.mod.loadfile_exports = loadfile_exports end _ml = modlib +modlib.mod.include"test.lua" --[[ --modlib.mod.include"test.lua" ]] +-- TODO verify localizations suffice return modlib \ No newline at end of file diff --git a/kdtree.lua b/kdtree.lua index 47f835b..5503bae 100644 --- a/kdtree.lua +++ b/kdtree.lua @@ -1,10 +1,11 @@ -- Localize globals -local assert, getfenv, math, modlib, rawget, setmetatable, table, unpack = assert, getfenv, math, modlib, rawget, setmetatable, table, unpack +local assert, math, modlib, setmetatable, table, unpack = assert, math, modlib, setmetatable, table, unpack -local class = getfenv(1) -local metatable = {__index = function(_self, key) - return rawget(class, key) -end} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} distance = modlib.vector.distance @@ -57,4 +58,7 @@ function get_nearest_neighbor(self, vector) return nearest_neighbor, min_distance end --- TODO insertion & deletion + rebalancing \ No newline at end of file +-- TODO insertion & deletion + rebalancing + +-- Export environment +return _ENV \ No newline at end of file diff --git a/log.lua b/log.lua index 5e4c43b..fca91d3 100644 --- a/log.lua +++ b/log.lua @@ -1,6 +1,10 @@ -- Localize globals local ipairs, minetest, modlib, os, pairs, table = ipairs, minetest, modlib, os, pairs, table +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- Log helpers - write to log, force writing to file minetest.mkdir(minetest.get_worldpath() .. "/logs") channels = {} @@ -77,3 +81,7 @@ minetest.register_on_shutdown( write_all_to_file() end ) + + +-- Export environment +return _ENV \ No newline at end of file diff --git a/math.lua b/math.lua index 506585a..dc43e10 100644 --- a/math.lua +++ b/math.lua @@ -1,6 +1,10 @@ -- Localize globals local math, minetest, modlib, os, string, table = math, minetest, modlib, os, string, table +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- Make random random math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock()) for _ = 1, 100 do math.random() end @@ -71,4 +75,7 @@ function fround(number) return sign * math.huge end return sign * powexp * (leading - mantissa / 0x800000) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/minetest.lua b/minetest.lua new file mode 100644 index 0000000..055c332 --- /dev/null +++ b/minetest.lua @@ -0,0 +1,12 @@ +local _ENV = setmetatable({}, {__index = _G}) +local function load(filename) + assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV) +end +load"misc" +load"collisionboxes" +load"liquid" +load"raycast" +load"wielditem_change" +load"colorspec" +load"schematic" +return _ENV \ No newline at end of file diff --git a/minetest/collisionboxes.lua b/minetest/collisionboxes.lua index 55bf06a..4ac1d17 100644 --- a/minetest/collisionboxes.lua +++ b/minetest/collisionboxes.lua @@ -1,6 +1,10 @@ -- Localize globals local assert, ipairs, math, minetest, pairs, table, type, vector = assert, ipairs, math, minetest, pairs, table, type, vector +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + -- 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 diff --git a/minetest/colorspec.lua b/minetest/colorspec.lua index b91b118..0536167 100644 --- a/minetest/colorspec.lua +++ b/minetest/colorspec.lua @@ -1,6 +1,10 @@ -- Localize globals local assert, error, math, minetest, setmetatable, tonumber, type = assert, error, math, minetest, setmetatable, tonumber, type +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + -- As in src/util/string.cpp named_colors = { aliceblue = 0xf0f8ff, diff --git a/minetest/liquid.lua b/minetest/liquid.lua index 09aa93f..659580f 100644 --- a/minetest/liquid.lua +++ b/minetest/liquid.lua @@ -1,6 +1,10 @@ -- Localize globals local minetest, modlib, pairs = minetest, modlib, pairs +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + 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` diff --git a/minetest/misc.lua b/minetest/misc.lua index 7f739b3..564d303 100644 --- a/minetest/misc.lua +++ b/minetest/misc.lua @@ -1,6 +1,10 @@ -- Localize globals local assert, minetest, modlib, next, pairs, string, table, type = assert, minetest, modlib, next, pairs, string, table, type +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + max_wear = 2 ^ 16 - 1 function override(function_name, function_builder) local func = minetest[function_name] diff --git a/minetest/raycast.lua b/minetest/raycast.lua index ee578ce..e94f22d 100644 --- a/minetest/raycast.lua +++ b/minetest/raycast.lua @@ -1,6 +1,10 @@ -- Localize globals local assert, math, minetest, modlib, pairs, setmetatable, vector = assert, math, minetest, modlib, pairs, setmetatable, vector +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + --+ Raycast wrapper with proper flowingliquid intersections function raycast(_pos1, _pos2, objects, liquids) local raycast = minetest.raycast(_pos1, _pos2, objects, liquids) diff --git a/minetest/schematic.lua b/minetest/schematic.lua index 6faaf31..2b12987 100644 --- a/minetest/schematic.lua +++ b/minetest/schematic.lua @@ -1,6 +1,10 @@ -- 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 +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + schematic = {} local metatable = {__index = schematic} diff --git a/minetest/wielditem_change.lua b/minetest/wielditem_change.lua index 0f49cd5..63387a9 100644 --- a/minetest/wielditem_change.lua +++ b/minetest/wielditem_change.lua @@ -1,6 +1,10 @@ -- Localize globals local minetest, modlib, pairs, table = minetest, modlib, pairs, table +-- Set environment +local _ENV = ... +setfenv(1, _ENV) + players = {} registered_on_wielditem_changes = {function(...) diff --git a/mod.lua b/mod.lua index eb19c89..fdef599 100644 --- a/mod.lua +++ b/mod.lua @@ -1,6 +1,18 @@ -- 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 +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +function loadfile_exports(filename) + local env = setmetatable({}, {__index = _G}) + local file = assert(loadfile(filename)) + setfenv(file, env) + file() + return env +end + -- get resource + dofile function include(modname, file) if not file then @@ -131,4 +143,7 @@ function configuration(modname) return schema:load({}, {error_message = true}) end return conf -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/persistence.lua b/persistence.lua index b59d1fe..b6a39eb 100644 --- a/persistence.lua +++ b/persistence.lua @@ -1,5 +1,9 @@ -- 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 +local assert, error, io, ipairs, loadfile, math, minetest, modlib, pairs, setfenv, setmetatable, table, type = assert, error, io, ipairs, loadfile, math, minetest, modlib, pairs, setfenv, setmetatable, table, type + +-- Set environment +local _ENV = {} +setfenv(1, _ENV) lua_log_file = {} local files = {} @@ -161,4 +165,7 @@ function lua_log_file:rewrite() end self:_rewrite() self:open() -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/player.lua b/player.lua index badc36f..47b4185 100644 --- a/player.lua +++ b/player.lua @@ -1,6 +1,10 @@ -- Localize globals local ipairs, minetest, modlib = ipairs, minetest, modlib +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + forbidden_names = {} function register_forbidden_name(name) forbidden_names[name] = true end @@ -78,4 +82,7 @@ function datatable(table, default) end) minetest.register_on_leaveplayer(function(player) table[player:get_player_name()] = nil end) return table -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/quaternion.lua b/quaternion.lua index 473ec1d..3adee90 100644 --- a/quaternion.lua +++ b/quaternion.lua @@ -1,6 +1,10 @@ -- Localize globals local math, modlib, pairs, unpack, vector = math, modlib, pairs, unpack, vector +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- TODO OOP, extend vector function from_euler_rotation(rotation) @@ -129,4 +133,7 @@ function to_euler_rotation_irrlicht(self) end return vector.apply(_calc(), math.deg) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/ranked_set.lua b/ranked_set.lua index 4b2b243..bfdd998 100644 --- a/ranked_set.lua +++ b/ranked_set.lua @@ -1,10 +1,11 @@ -- Localize globals -local assert, getfenv, modlib, pairs, rawget, setmetatable, table = assert, getfenv, modlib, pairs, rawget, setmetatable, table +local assert, modlib, pairs, setmetatable, table = assert, modlib, pairs, setmetatable, table -local class = getfenv(1) -local metatable = {__index = function(_self, key) - return rawget(class, key) -end} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} comparator = modlib.table.default_comparator @@ -314,4 +315,7 @@ function get_by_rank(self, rank) tree = right end until not tree -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/schema.lua b/schema.lua index cdc4972..6caca08 100644 --- a/schema.lua +++ b/schema.lua @@ -1,10 +1,11 @@ -- 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 assert, error, ipairs, math, minetest, modlib, pairs, setmetatable, table, tonumber, tostring, type = assert, error, ipairs, math, minetest, modlib, pairs, setmetatable, table, tonumber, tostring, type -local class = getfenv(1) -local metatable = {__index = function(_self, key) - return rawget(class, key) -end} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} function new(def) -- TODO type inference, sanity checking etc. @@ -298,4 +299,7 @@ function load(self, override, params) end if self.func then self.func(override) end return override -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/table.lua b/table.lua index b35f072..ca14fcf 100644 --- a/table.lua +++ b/table.lua @@ -1,6 +1,10 @@ -- 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 +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + -- Table helpers function map_index(table, func) @@ -589,4 +593,7 @@ function repetition(value, count) table[index] = value end return table -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/text.lua b/text.lua index c34583c..8f5e9a8 100644 --- a/text.lua +++ b/text.lua @@ -1,6 +1,10 @@ -- Localize globals local math, modlib, pairs, setmetatable, string, table = math, modlib, pairs, setmetatable, string, table +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + 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 @@ -166,4 +170,7 @@ function handle_ifdefs(code, vars) end table.insert(finalcode, string.sub(code, after_endif + 2)) return table.concat(finalcode, "") -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/trie.lua b/trie.lua index 06dbdc6..1231fa1 100644 --- a/trie.lua +++ b/trie.lua @@ -1,10 +1,11 @@ -- Localize globals -local getfenv, math, next, pairs, rawget, setmetatable, string, table, unpack = getfenv, math, next, pairs, rawget, setmetatable, string, table, unpack +local math, next, pairs, setmetatable, string, table, unpack = math, next, pairs, setmetatable, string, table, unpack -local class = getfenv(1) -local metatable = {__index = function(_self, key) - return rawget(class, key) -end} +-- Set environment +local _ENV = {} +setfenv(1, _ENV) + +local metatable = {__index = _ENV} function new(table) return setmetatable(table or {}, metatable) end @@ -124,4 +125,7 @@ function find_longest(self, query, query_offset) end end return last_leaf, leaf_pos -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file diff --git a/vector.lua b/vector.lua index f76062e..e844ad6 100644 --- a/vector.lua +++ b/vector.lua @@ -1,8 +1,11 @@ -- Localize globals -local assert, getfenv, math, modlib, pairs, rawget, rawset, setmetatable, unpack, vector = assert, getfenv, math, modlib, pairs, rawget, rawset, setmetatable, unpack, vector +local assert, math, modlib, pairs, rawset, setmetatable, unpack, vector = assert, math, modlib, pairs, rawset, setmetatable, unpack, vector + +-- Set environment +local _ENV = {} +setfenv(1, _ENV) local mt_vector = vector -local class = getfenv(1) index_aliases = { x = 1, @@ -19,9 +22,10 @@ metatable = { if index ~= nil then return table[index] end - return rawget(class, key) + return _ENV[key] end, __newindex = function(table, key, value) + -- TODO local index = letters[key] if index ~= nil then return rawset(table, index, value) @@ -225,4 +229,7 @@ function triangle_normal(triangle) local point_1, point_2, point_3 = unpack(triangle) local edge_1, edge_2 = subtract(point_2, point_1), subtract(point_3, point_1) return normalize(cross3(edge_1, edge_2)) -end \ No newline at end of file +end + +-- Export environment +return _ENV \ No newline at end of file