Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
Created August 2, 2016 05:11
Show Gist options
  • Save CoderPuppy/85d387db8033e6754cf0cd3fef3d602d to your computer and use it in GitHub Desktop.
Save CoderPuppy/85d387db8033e6754cf0cd3fef3d602d to your computer and use it in GitHub Desktop.
local function formArguments( class, target )
local reg = class:getRegistry()
local constructor, alias, args = reg.constructor, reg.alias, target.arguments
local returnArguments, trailingTable = {n=0;}, {}
if not constructor then return nil end
local argumentTypes = constructor.argumentTypes
local ordered, set, target = constructor.orderedArguments, {}
for i = 1, #ordered do
target = ordered[ i ]
returnArguments[ i ] = XML.convertArgType( args[ target ], argumentTypes[ alias[ target ] or target ] )
set[ ordered[ i ] ] = true
end
returnArguments.n = #ordered
for argName, argValue in pairs( args ) do
if not set[ argName ] then
trailingTable[ argName ] = XML.convertArgType( argValue, argumentTypes[ alias[ argName ] or argName ] )
end
end
if next( trailingTable ) then
returnArguments[ #ordered + 1 ] = trailingTable
returnArguments.n = returnArguments.n + 1
end
return unpack( returnArguments, 1, returnArguments.n )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment