質問を正しく理解している場合は、on_clickハンドラーが属するオブジェクトをon_clickハンドラーから参照できるようにする必要があります。これを行うには、次のステートメントを分割する必要があります。
local card = { name = "my card" }
local object = {
identifier = "hand:" .. card.name,
area = { x, y, 100, 100 },
}
object.on_click = function()
-- Code goes here
-- you can reference card and object here (they are upvalues in this context)
print(card.name, object.area[3])
end
object.click()
on_click少し異なる方法で定義することもできます。この場合object、暗黙的に宣言されたself変数として取得します(これも少し異なる方法で呼び出すことに注意してください)。
function object:on_click()
-- Code goes here
-- you can reference card and object here
print(card.name, self.area[3])
end
object:click() -- this is the same as object.click(object)