功能类似cpp的bind,打包一个函数
先上代码:
function _1() end function _2() end function _3() end function _4() end function _5() end function _6() end --@Ability: -- better implement of packfunc --@Example: -- local f = bind(print,_1,":my",_1,"is",_2,"!") -- f("name","leo") -- f("age",18) function bind(func,...) local _placeholder = { [_1] = 1, [_4] = 2, [_2] = 3, [_5] = 4, [_3] = 5, [_6] = 6, } local _argsSuper = {...} return function(...) local _argsOut = {} local _argsInner = {...} for i,v in pairs(_argsSuper) do _argsOut[i] = _placeholder[v] and _argsInner[_placeholder[v]] or _argsSuper[i] end return func(unpack(_argsOut)) end end