sorcery  Diff

Differences From Artifact [58ff591804]:

To Artifact [3b59932455]:


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40





41
42
43
44
45
46
47
	argjoin(arg, nxt, ...)
		if arg and not nxt then return tostring(arg) end
		if not arg then return "(nil)" end
		return tostring(arg) .. ' ' .. argjoin(nxt, ...)
	end

	local logger = function(module)
		local emit = function(lvl)
			return function(...)
				if module then
					minetest.log(lvl,string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
				else
					minetest.log(lvl,string.format('[%s] %s',selfname,argjoin(...)))
				end
			end
		end
		return {
			info = emit('info');
			warn = emit('warning');
			err = emit('error');
			act = emit('action');
		}





	end;

	local stage = function(s,...)
		logger().info('entering stage',s)
		local f = sorcery.cfg(s .. '.lua')
		if test(f) then return loadfile(f)(...) or true end
		return false







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
	argjoin(arg, nxt, ...)
		if arg and not nxt then return tostring(arg) end
		if not arg then return "(nil)" end
		return tostring(arg) .. ' ' .. argjoin(nxt, ...)
	end

	local logger = function(module)
		local lg = {}
		local setup = function(fn, lvl)
			lvl = lvl or fn
			local function emit(...)
				local call = (fn == 'fatal') and error
					or function(str) minetest.log(lvl, str) end
				if module
					then call(string.format('[%s :: %s] %s',selfname,module,argjoin(...)))
					else call(string.format('[%s] %s',selfname,argjoin(...)))
				end
			end
			lg[fn       ] = function(...) emit(...)                end
			lg[fn .. 'f'] = function(...) emit(string.format(...)) end -- convenience fn
		end
		setup('info')
		setup('warn','warning')
		setup('err','error')
		setup('act','action')
		setup('fatal')
		return lg
	end;

	local stage = function(s,...)
		logger().info('entering stage',s)
		local f = sorcery.cfg(s .. '.lua')
		if test(f) then return loadfile(f)(...) or true end
		return false