Lua返回一个Closures函数实例

这篇文章主要介绍了Lua返回一个Closures函数实例,本文直接给出代码实例,需要的朋友可以参考下

复制代码 代码如下:

do
 function Button(x)
  print("Call Button");
  x.action();
  print(x.label);
 end

 function add_to_display(digit)
  print("Call add_to_display");
  print(digit);
 end

 function digitButton(digit)
  return Button{//return a table and the function(Button), it means that the Button receives the param(the table{...})
      label = tostring(digit),
      action = function()
         print("digit: ", digit);
         add_to_display(digit);
         end
       }

 end

 local fun = digitButton(3);

end

以上就是Lua返回一个Closures函数实例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Lua