lua中的前向函数参数arg

时间:2012-11-08 09:37:30

标签: function parameters lua arguments

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

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

-- 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" )

1 个答案:

答案 0 :(得分:0)

在新的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