Difference between revisions of "Module:Arguments"

From Minetest Wiki
Jump to navigation Jump to search
(Created page with "local p = {} function p.getArgs(frame, options) options = options or {} local metatable = {} function metatable:__index(key) local arg = frame.args[key] ...")
 
m (Added makeInvokeFunc)
Line 13: Line 13:
 
     end
 
     end
 
     return setmetatable({}, metatable)
 
     return setmetatable({}, metatable)
 +
end
 +
 +
function p.makeInvokeFunc(func, options)
 +
    return function(frame)
 +
        local args = getArgs(frame, options)
 +
        return func(args)
 +
    end
 
end
 
end
  
 
return p
 
return p

Revision as of 18:01, 7 May 2017

local p = {}

function p.getArgs(frame, options)

   options = options or {}
   local metatable = {}
   function metatable:__index(key)
       local arg = frame.args[key]
       if arg == nil and options.inherited then
           local parent = frame:getParent()
           arg = parent and parent.args[key] or nil
       end
       return arg
   end
   return setmetatable({}, metatable)

end

function p.makeInvokeFunc(func, options)

   return function(frame)
       local args = getArgs(frame, options)
       return func(args)
   end

end

return p