Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (23 sloc) 639 Bytes

knife.bind

Bind arguments to functions.

local Bind = require 'knife.bind'

Bind (func, ...)

Bind arguments to a function.

Parameters

  • function func

    Function to bind arguments to.

  • mixed ...

    Arguments to bind to the function.

Returns

  • Bound function. Invokes func with bound arguments, followed by any arguments passed when invoking the bound function.

Example

local function speak (person, phrase, audience)
  print(person .. ' says ' .. phrase .. ' to ' .. audience)
end

local bobGreet = Bind(speak, 'Bob', 'hi')

bobGreet('you') -- prints "Bob says hi to you"