Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
__indexのメタテーブルを設定してから、次のfooいずれかを呼び出すと:
__index
foo
print(foo.x)
また
print(foo.x())
__indexカスタム関数でこれら 2 つの呼び出しを区別する方法はありますか?
いいえ、それらは 2 つの異なるものではないためです。これらは同じ操作です。テーブルを取得して、という名前のフィールドにアクセスしますx。結果に対して関数を呼び出そうとするという事実は、まったく無関係です。結局のところ、これを行うことができます:
x
local temp = foo.x temp()
そして、それは 100% 同等の Lua コードでなければなりません。