mirror of
https://git.0x7be.net/dirk/uniham.git
synced 2024-11-19 22:03:46 +01:00
45 lines
1.3 KiB
Lua
45 lines
1.3 KiB
Lua
-- Localize & Initialize
|
|
local register_hammer = uniham.register_hammer
|
|
local modpath = uniham.modpath
|
|
local registry = modpath..DIR_DELIM..'registry'
|
|
local depends = io.open(modpath..DIR_DELIM..'depends.txt', 'rb')
|
|
local log_prefix = '['..minetest.get_current_modname()..'] '
|
|
|
|
|
|
-- Check if a file exists
|
|
--
|
|
-- This function validates the existence of a file by trying to open the file
|
|
-- for reading. If this succeeds the file is present.
|
|
--
|
|
-- @param file_name The file name (path) to be checked
|
|
local file_exists = function (file_name)
|
|
local f = io.open(file_name ,'r')
|
|
if f ~= nil then
|
|
io.close(f)
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
|
|
-- Check if the depends.txt file was read properly
|
|
-- Iterate over all lines
|
|
-- Check if the mod exists
|
|
-- Check if a registry file exists
|
|
-- dofile() the file and print a log message
|
|
if depends ~= nil then
|
|
local lines = {}
|
|
for line in depends:lines() do
|
|
local modname = line:gsub('?', '')
|
|
if minetest.get_modpath(modname) then
|
|
local registry_file = registry..DIR_DELIM..modname..'.lua'
|
|
if file_exists(registry_file) then
|
|
dofile(registry_file)
|
|
local message = 'Loaded built-in '..modname..' support'
|
|
minetest.log('action', log_prefix..message)
|
|
end
|
|
end
|
|
end
|
|
end
|