Skip to content

Commit

Permalink
knife.bind improvement (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tst2005 authored and airstruck committed Sep 17, 2018
1 parent 9052361 commit 9d24944
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions knife/bind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ local function buildHelper (argCount)
if helperCache[argCount] then
return helperCache[argCount]
end
local argList1 = { 'f' }
local argList2 = {}
local argList = {}
for index = 1, argCount do
argList1[index + 1] = 'a' .. index
argList2[index] = 'a' .. index
argList[index] = 'a' .. index
end
argList2[argCount + 1] = '...'
local source = 'return function(' .. tconcat(argList1, ', ') ..
') return function(...) return f(' .. tconcat(argList2, ', ') ..
') end end'
local sep = (argCount>=1 and ", " or "")
local source = 'return function(f'.. sep .. tconcat(argList, ', ') ..
') return function(...) return f(' .. tconcat(argList, ', ') ..
sep .. '...) end end'
local helper = loadstring(source)()
helperCache[argCount] = helper
return helper
Expand Down

0 comments on commit 9d24944

Please sign in to comment.