Skip to main content

Posts

Showing posts from March, 2015

[Lua] 簡易模擬 C# Delegate Type 行為

因為工作需求,準備開始學習 C#,這兩天研究一些公開的 Unity 原始碼發現 C# 有個 Delegate Type 很有意思,它可以利用 + 與 - 將需要搭配執行的 function 指派到委任者然後一起執行。如: //C#, d1 and d2 are functions allMethodsDelegate += d1; allMethodsDelegate += d2; allMethodsDelegate(); // d1(), d2() allMethodsDelegate -= d2; allMethodsDelegate(); // d1() 參考資料: 使用委派 (C# 程式設計手冊) Edit: 03, 08, 2015, 感謝 fb@shanyungyang 的提醒可以使用 Lua 的 metamethod 實作,為了達到屬性能往下傳,本來是打算採用 * / 但是又怕太混亂,最後就是由另外一個 meta2 來達到效果囉! ^^