Own proxy extended class / Adding own objects to physics

Hi Corona people,

I’m new to Corona and Lua and come from Java programming, so I currently try to “convert” my Java OOP thinkink to Corona and Lua. I searched quite a while and didn’t found the best practice to define own objects with own functions which are still compatible with the Corona API, e.g. the physics engine.

Let me explain it with some Lua / Pseudocode:

------ Planets.lua extends the Corona Proxy class?!------- local P = {} local planet local function create()       planet = display.newCircle( display.contentCenterX + 60, display.contentCenterY + 60, 80 ) -- return new Planet object??? end local function doOwnFunction() -- Do some stuff with "planet" variable end P.create = create return P ------ Main.lua ------ local planets = require("src.planet") local planet1 = planets.create() physics.addBody( planet1, "dynamic" ) -- Object is still compatible with API planet1.doOwnFunction() -- Object is extentable with own code

Is this even the right approach or should I handle this need completely different in Lua?

That’s the way how I handle stuff in Corona. You can also take a look at some useful tutorials from the official Lua website.

https://www.lua.org/pil/16.html

http://lua-users.org/wiki/ObjectOrientationTutorial

http://lua-users.org/wiki/LuaClassesWithMetatable

http://lua-users.org/wiki/ObjectOrientedProgramming (30log is one of the simplest modules here)

You also need to assign doOwnFunction() to P if you want to call it as a method.

Rob

That’s the way how I handle stuff in Corona. You can also take a look at some useful tutorials from the official Lua website.

https://www.lua.org/pil/16.html

http://lua-users.org/wiki/ObjectOrientationTutorial

http://lua-users.org/wiki/LuaClassesWithMetatable

http://lua-users.org/wiki/ObjectOrientedProgramming (30log is one of the simplest modules here)

You also need to assign doOwnFunction() to P if you want to call it as a method.

Rob