sorcery  Diff

Differences From Artifact [58ff591804]:

To Artifact [3b59932455]:


    19     19   	argjoin(arg, nxt, ...)
    20     20   		if arg and not nxt then return tostring(arg) end
    21     21   		if not arg then return "(nil)" end
    22     22   		return tostring(arg) .. ' ' .. argjoin(nxt, ...)
    23     23   	end
    24     24   
    25     25   	local logger = function(module)
    26         -		local emit = function(lvl)
    27         -			return function(...)
    28         -				if module then
    29         -					minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
    30         -				else
    31         -					minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...)))
           26  +		local lg = {}
           27  +		local setup = function(fn, lvl)
           28  +			lvl = lvl or fn
           29  +			local function emit(...)
           30  +				local call = (fn == 'fatal') and error
           31  +					or function(str) minetest.log(lvl, str) end
           32  +				if module
           33  +					then call(string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
           34  +					else call(string.format('[%s] %s',selfname,argjoin(...)))
    32     35   				end
    33     36   			end
           37  +			lg[fn       ] = function(...) emit(...)                end
           38  +			lg[fn .. 'f'] = function(...) emit(string.format(...)) end -- convenience fn
    34     39   		end
    35         -		return {
    36         -			info = emit('info');
    37         -			warn = emit('warning');
    38         -			err = emit('error');
    39         -			act = emit('action');
    40         -		}
           40  +		setup('info')
           41  +		setup('warn','warning')
           42  +		setup('err','error')
           43  +		setup('act','action')
           44  +		setup('fatal')
           45  +		return lg
    41     46   	end;
    42     47   
    43     48   	local stage = function(s,...)
    44     49   		logger().info('entering stage',s)
    45     50   		local f = sorcery.cfg(s .. '.lua')
    46     51   		if test(f) then return loadfile(f)(...) or true end
    47     52   		return false