當前位置:編程學習大全網 - 網站源碼 - lua functions callback怎麽使用

lua functions callback怎麽使用

舉個例子:

local?m?=?{}?

local?list?=?{name="hello",age=12}?

m.call_back_fun_print?=?function(printID)?

print(printID?..?"-->"?..?list[printID])?

end?

m.add_list?=?function(key,value,call_back_fun)?

key?=?tostring(key)?

list[key]?=?value?

call_back_fun(key)?

end?

m.add_list("address","beijing",m.call_back_fun_print)?--address-->beijing?

return?m

註:C、C++和Pascal允許將函數指針作為參數傳遞給其它函數。其它語言,例如JavaScript,Python,Lua,Perl和PHP,允許簡單的將函數名作為參數傳遞。

詳情可參考這篇博客:/shimazhuge/article/details/41680909?utm_source=tuicool&utm_medium=referral

望對妳有所幫助!

  • 上一篇:未定義標識符amount怎麽解決
  • 下一篇:特洛伊馬源代碼大全
  • copyright 2024編程學習大全網