Removed several uses of implicit 'arg' from variadic arguments; Loona:shref()
authorTimm S. Mueller <tmueller@neoscientists.org>
Fri, 23 Jan 2009 13:22:15 +0100
changeset 25421aabb5e37a6
parent 253 c845ac1bb22c
child 255 63e76b4e3956
Removed several uses of implicit 'arg' from variadic arguments; Loona:shref()
now checks for duplicate arguments
cgi-bin/tek/class/loona.lua
     1.1 --- a/cgi-bin/tek/class/loona.lua	Tue Jan 20 22:46:39 2009 +0100
     1.2 +++ b/cgi-bin/tek/class/loona.lua	Fri Jan 23 13:22:15 2009 +0100
     1.3 @@ -41,7 +41,7 @@
     1.4  -------------------------------------------------------------------------------
     1.5  
     1.6  module("tek.class.loona", tek.class)
     1.7 -_VERSION = "LOona Class 5.9"
     1.8 +_VERSION = "LOona Class 5.10"
     1.9  
    1.10  -------------------------------------------------------------------------------
    1.11  --	Markup:
    1.12 @@ -291,7 +291,7 @@
    1.13  
    1.14  function Loona:recursesections(s, func, ...)
    1.15  	for _, e in ipairs(s) do
    1.16 -		local udata = { func(self, s, e, unpack(arg)) }
    1.17 +		local udata = { func(self, s, e, ...) }
    1.18  		if e.subs then
    1.19  			self:recursesections(e.subs, func, unpack(udata))
    1.20  		end
    1.21 @@ -505,7 +505,7 @@
    1.22  	local f, msg = open(tempname, "wb")
    1.23  	assert(f, self:dbmsg("Error opening section file for writing", msg))
    1.24  	lib.dump(self.sections, function(...)
    1.25 -		f:write(unpack(arg))
    1.26 +		f:write(...)
    1.27  	end)
    1.28  	f:close()
    1.29  	local success, msg = rename(tempname, self.indexfname)
    1.30 @@ -524,7 +524,7 @@
    1.31  
    1.32  function Loona:runboxed(func, envitems, ...)
    1.33  	local fenv = {
    1.34 - 		arg = arg,
    1.35 + 		arg = { ... },
    1.36   		loona = self
    1.37   	}
    1.38   	if envitems then
    1.39 @@ -546,7 +546,7 @@
    1.40  	local parsed, msg = self:loadhtml(f, "loona:out", fname2)
    1.41  	msg = msg and (type(msg) == "string" and msg or msg.txt)
    1.42  	assert(parsed, self:dbmsg("Syntax error", msg))
    1.43 -	return self:runboxed(parsed, nil, unpack(arg))
    1.44 +	return self:runboxed(parsed, nil, ...)
    1.45  end
    1.46  
    1.47  
    1.48 @@ -557,9 +557,20 @@
    1.49  	for _, a in ipairs(arg) do
    1.50  		local key, val = a:match("^([%w_]+)=(.*)$")
    1.51  		if key and val then -- "arg=val" sets/overrides argument
    1.52 -			insert(args2, { name = key, value = val })
    1.53 +			local n = args2[key] -- previously set?
    1.54 +			if n then
    1.55 +				-- overwrite argument
    1.56 +				args2[n] = { name = key, value = val }
    1.57 +			else
    1.58 +				-- create argument
    1.59 +				insert(args2, { name = key, value = val })
    1.60 +				args2[key] = #args2 -- remember position
    1.61 +			end
    1.62  		elseif self.args[a] then -- just "arg" propagates argument
    1.63 -			insert(args2, { name = a, value = self.args[a] })
    1.64 +			if not args2[a] then
    1.65 +				insert(args2, { name = a, value = self.args[a] })
    1.66 +				args2[a] = #args2 -- remember position
    1.67 +			end
    1.68  		end
    1.69  	end
    1.70  	local doc = self:getdocname(section, #args2 > 0)
    1.71 @@ -584,6 +595,7 @@
    1.72  --	produce link target, implicit propagation of lang, profile, session
    1.73  
    1.74  function Loona:href(section, ...)
    1.75 +	local arg = { ... }
    1.76  	if self.session then
    1.77  		insert(arg, 1, "profile")
    1.78  		insert(arg, 1, "session")
    1.79 @@ -603,7 +615,7 @@
    1.80  --	internal link, implicit propagation of lang, profile, session
    1.81  
    1.82  function Loona:link(section, text, ...)
    1.83 -	return self:ilink(self:href(section, unpack(arg)), text or section,
    1.84 +	return self:ilink(self:href(section, ...), text or section,
    1.85  	' class="intlink"')
    1.86  end
    1.87  
    1.88 @@ -618,14 +630,14 @@
    1.89  --	plain link, no implicit argument propagation
    1.90  
    1.91  function Loona:plink(section, text, ...)
    1.92 -	return self:ilink(self:shref(section, arg), text or section)
    1.93 +	return self:ilink(self:shref(section, { ... }), text or section)
    1.94  end
    1.95  
    1.96  
    1.97  --	user interface link, implicit propagation of lang, profile, session
    1.98  
    1.99  function Loona:uilink(section, text, ...)
   1.100 -	return self:ilink(self:href(section, unpack(arg)), text or section,
   1.101 +	return self:ilink(self:href(section, ...), text or section,
   1.102  	' class="uilink"')
   1.103  end
   1.104  
   1.105 @@ -716,7 +728,7 @@
   1.106  	render.link = render.link or
   1.107  		function(self, level, path, label, active, ...)
   1.108  			self:out(('<a %shref="%s">%s</a>\n'):format(active and
   1.109 -				'class="active" ' or "", self:href(path, unpack(arg)), label))
   1.110 +				'class="active" ' or "", self:href(path, ...), label))
   1.111  		end
   1.112  	render.listbegin = render.listbegin or
   1.113  		function(self, level) -- , numvis, path