Module:Args: Difference between revisions

Want an adless experience? Log in or Create an account.
add values() function to unwrap a particular node
(this handles parsing flattened arg trees into lua tables. I don't like that you have to call :val() on everything though...)
 
(add values() function to unwrap a particular node)
Line 8: Line 8:
end
end


-- get the Arg node's value, if it has one
function Arg:val()
function Arg:val()
   return self.__value
   return self.__value
end
-- get the values of the Arg node's direct children
-- this is used to re-flatten/unwrap a particular piece of an Arg tree
function Arg:values()
  local vals = {}
  for k, v in pairs( self ) do
    if type( v ) == 'table' and v.val then
      vals[k] = v:val()
    end
  end
  return vals
end
end


Line 30: Line 44:


function p.parse( args )
function p.parse( args )
   local parsedArgs = {}
   local parsedArgs = Arg.new()
   for k, v in pairs( args ) do
   for k, v in pairs( args ) do
     insertInto( parsedArgs, k, v )
     insertInto( parsedArgs, k, v )