0

我想重写一个函数来检查它的参数值,但是调用它并正常传递原始参数。这可能吗?我正在使用 www.coronalabs.com 的 Corona SDK

我目前不起作用的代码是:

-- getting a refrence to the original function so i can replace it with my overriding function
local newcircle = display.newCircle

-- my override
display.newCircle = function(...)
-- attempt to pass the parameters to this function on to the real function
local t = {...}
newcircle(unpack(t))
end

-- calling the overridden function as if it were normal
display.newCircle( display.newGroup(), "image.png" )
4

1 回答 1

1

在您的新display.newCircle实现中,您使用的是未定义的t表和已弃用的arg自动表。

尝试这个 :

-- my override
display.newCircle = function(...)
    local t = {...} -- you need to collect arguments to a table
    -- dumb use of override
    print(t[1])
    -- attempt to pass the parameters to this function on to the real function
    newcircle(unpack(t))
end
于 2012-11-08T09:57:05.287 回答