ポストフックに関するトピックを 1 つ見つけましたが、それは私が達成したいことと同じではないと思います。 私が見つけたトピック
必要なものは次のとおりです。
local someBoolean = false
function doSomething() -- this is the function used in __index in a proxy table
someBoolean = true
return aFunction -- this is function that we can NOT alter
end
リターン後にコード「someBoolean = false」を実行できるようにする必要があります...(はい、それが起こるはずがないことはわかっています:p)aFunctionには他の関数自体が含まれている可能性があるため、someBooleanを全体でtrueにする必要がありますaFunction のスコープですが、その後は false に戻す必要があります
うまく説明できていなかったら申し訳ありません。私の実際のプロジェクトの関連コードをコピーして貼り付けるのは大きすぎるので、あなたの時間を無駄にしたくありません。私はしばらくこれに固執していましたが、それを理解できないようです...
(編集:関数は実際にはプロキシテーブルの __index 関数であるため、関数の後に someBoolean = false を置くことはできません)
編集:関連するコード。少しはっきりしているといいのですが
local function objectProxyDelegate(t, key)
if not done then -- done = true when our object is fully initialised
return cls[key] -- cls is the class, newinst is the new instance (duh...)
end
print("trying to delegate " .. key)
if accessTable.public[key] then
print(key .. " passed the test")
objectScope = true
if accessTable.static[key] then -- static function. return the static one
return cls[key] -- we need to somehow set objectScope back to false after this, otherwise we'll keep overriding protected/private functions
else
return newinst[key]
end
elseif objectScope then
print("overridden protected/private")
return cls[key]
end
if accessTable.private[key] then
error ("This function is not visible. (private)", 2)
elseif accessTable.protected[key] then
error ("This function is not visible to an instance. (protected)", 2)
else
error ("The function " .. key .. " doesn't exiist in " .. newinst:getType(), 2) -- den deze...
end
end