我想将一个函数作为参数传递,要传递的函数需要两个参数。我想要第一个参数填充,但第二个参数不填充。这是示例:
function a(firstarg, secondarg)
print ("this is the" .. firstarg .. "to the a function and the b function gave it ".. secondarg)
end
function b(givenfunction)
givenfunction("the second argument.")
对该函数的所需调用:
b(a("first call"))
b(a("second call"))
执行的期望输出:
this is the first call to the a function and the b function gave it the second argument.
this is the second call to the a function and the b function gave it the second argument.
我怎样才能做到这一点?
function inner(firstarg, secondarg)
print ("this is the" .. firstarg .. "to the a function and the b function gave it ".. secondarg)
end
function a(firstarg)
return function (secondarg)
return inner(firstarg, secondarg)
end
end
function b(givenfunction)
givenfunction("the second argument.")
end
b(a("first call"))
b(a("second call"))
像魅力一样工作。谢谢!:)