Lua question : how to intercept function call

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Lua question : how to intercept function call

Post by TsT »

Hello

I'm trying to implement the missing love feature to draw on different layers.

I have almost finished but I need to improve my way of intercepting love function.

For now I have something like:

Code: Select all


        realfunc = love.graphics.rectangle
        love.graphics.rectangle = function(...)
                myfunc("something", arg)
        end

        myfunc = function(cmd, a)
                realfunc([i][b]a[1], a[2], a[3], a[4][/b][/i])
        end

Is anyone know how to call a function not with one table argument, but with all item of the table as arguments ?

I have try to use loadstring but it's not running when I have symbol (table, function, ...) in item of the table.

Best Regards,
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
hagish
Citizen
Posts: 85
Joined: Thu May 01, 2008 12:51 pm
Contact:

Re: Lua question : how to intercept function call

Post by hagish »

not sure if i understand you correctly but unpack should do it:

Code: Select all

love.graphics.rectangle = function(...)
                myfunc("something", unpack(arg))
end
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lua question : how to intercept function call

Post by bartbes »

I'm not sure, but I thought ... returns all the arguments

Code: Select all

function test(...)
print(...)
end
should call print with all arguments.

PS: posting on PS3
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: Lua question : how to intercept function call

Post by TsT »

Thanks for all, unpack is exactly what I need ^^
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Lua question : how to intercept function call

Post by Lord Tim »

bartbes wrote:I'm not sure, but I thought ... returns all the arguments

Code: Select all

function test(...)
print(...)
end
should call print with all arguments.

PS: posting on PS3
You just put the "..." in the parenthesis. to access them you use "arg" as a table.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lua question : how to intercept function call

Post by bartbes »

Got that part, but I've recently found a snippet using ... as argument.

However the lua manual lacks some things, and this is one of them. And what about the __index field? (unless they changed it)
I like the LÖVE documentation more (although there are hidden functions too).
User avatar
Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

Re: Lua question : how to intercept function call

Post by Kaze »

Lord Tim wrote:
bartbes wrote:I'm not sure, but I thought ... returns all the arguments

Code: Select all

function test(...)
print(...)
end
should call print with all arguments.

PS: posting on PS3
You just put the "..." in the parenthesis. to access them you use "arg" as a table.
"..." is the same as "unpack(arg)"

Code: Select all

function dostuff(...)
    stuff1(...)
    stuff2(...)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 21 guests