Referencing object functions?

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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Referencing object functions?

Post by grump »

ivan wrote: Sun Feb 25, 2018 1:30 pmPS. Hope you don't mind, but I've added your nickname to the game's end credits.
Not at all, thanks.
coffeecat
Prole
Posts: 29
Joined: Sun Sep 13, 2015 4:10 pm

Re: Referencing object functions?

Post by coffeecat »

I'm not sure why you need Body_getPosition, but if you only need a semantically equivalent function, you can use a simple wrapper:

Code: Select all

local function Body_getPosition(body)
  return body:getPosition()
end
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Referencing object functions?

Post by ivan »

I'm porting a game that uses a slightly different API for Box2D so it's kind of useful to add/modify the functions for Bodies,Joints, etc.
Like for example, contact:getOther is quite useful but love.physics doesn't include that function.
Also, with the getregistry technique, you can get a direct reference to the functions, (circumventing metatables), which is x0.85 faster in LuaJIT and considerably faster than plain Lua.
Not a big deal but might come in handy if you like to squeeze every last drop of performance.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 210 guests