Is Corona Implementing Its Own Oop Process?

Wow, the new “code” tags really suck. Not only is the white on black text completely illegible (come on Corona guys, do you guys just take random guesses for color schemes or do you actually research this? I’ll give you a hint: any first year typography student knows that this is a no-no), but also so weird paragraph tags are all over the place. Strange.

 

Well, pretty underwhelmed with the new forums so far!

Try the using the lua tag instead of code tag. It should format better  :slight_smile:

Hey CraftyDeano,

 

Thanks for the suggestion - only now one empty line is inserted inbetween every line of code - so I changed it back to “code” tag. Sheesh! If it ain’t broke…

Edit: I see what you mean! 

I followed this http://lua-users.org/wiki/ObjectOrientedProgramming and found it pretty straightforward without doing special stuff… :S why would you use something different?

It may be personal but I find these tutorials to be geared towards “programmers” instead of casual coders - no challenge for me since I’m a programmer, but I see people having issues with this.

 

I fully agree that these tutorials do document the right way to do OOP with Lua, without needing other frameworks on top, but I do feel that these tutorials fall way short of OOP programming specifically geared towards Corona coders (meaning: for use with display objects that have enterFrame and touch listeneners, and need to be able to remove themselves smartly etcetera). As soon as you dive into these topics you notice that in-depth information on OOP and Corona is sorely lacking.

 

Out of curiosity, matrix2000, do you incorporate enterFrame listeners, timers, etc… in your OOP implementation? If so, do you mind posting some code?

Yes, I do, I ussually wrap them up in another function:

 

My objects have a listeners list then when I want to propagate an event I do as following:

 

[lua]

for i, v in pairs(self._listeners) do

 

  event._params = self._params – my own params injected in the event.

  v.listener[v.fun](v.listener, event) – my call to the listener.

end

 

[/lua]

method 1:

For enter frame, I define an “object:enterFrame(event)” method, this one you should call it exactly like this or use method 2

 

Runtime:addEventListener( “enterFrame”, self )

 

method 2

local function callback(event)

            object:callMyRealFunction(event)

end

Runtime:addEventListener( callback )

 

and for timers same thing:

 

 

timer.performWithDelay(700, function()

        object:function(parameters)

    end 

as you see you can wrap them up easily (of course this code applied with care and to your own structure).

 

I hope this helps to everyone.

 

 

 

This is a fantastic news! I have recently been looking at Codea (app for the ipad to build app/prototypes) and they did implement a “class” system. It looks so nice to use and was kind of jealous since Corona did not implement it directly out of the box. I am really confused about all the implementations** I have seen around the forum so an “official” Corona SDK implementation of OOP is a great news for me newbie!

Can’t wait!

Mo

** Unfortunately there is a lot of description of OOP implementation but very little tutorial or even better a full game sample using OOP that I am aware of. I particularly LOVE “ardentKid” tutorials about OOP. I just wish one day he can share a full sample app using it ;) 

I haven’t seen anything that suggests there is a Corona SDK implementation of OOP.  As far as I know you have to use one of the Lua styles out there.  Corona does only support an older version of Lua but there is still a lot of options.

Hi cspense, I have notice this link:

http://docs.coronalabs.com/daily/api/type/CoronaPrototype/initialize.html

Which gives the following example in the API doc there:

local MyClass = CoronaPrototype:newClass( “MyClass” )

function MyClass:initialize()
– custom init
self.foo = “bar”
return self
end

local instance = MyClass:new()
print( instance.foo )

Don’t you think this means that Corona is about to introduce their own OOP implementation (which will be a GREAT news!)?

Mo

That is for file objects, not OOP.

Are you sure? Why file objects (what a heck a file object is anyway?)  would need this type of things? Oh man you destroyed my dream with one sentence…LOL

Thanks cpsence

Mo

You might be right, but take a look at this:

http://docs.coronalabs.com/daily/api/type/File/index.html

Thanks, that’s good to know. Still it is confusing that they will have such as example for the Corona Prototype above? I hope I am right :). It will make clean coding so much easier! Mo

This is a fantastic news! I have recently been looking at Codea (app for the ipad to build app/prototypes) and they did implement a “class” system. It looks so nice to use and was kind of jealous since Corona did not implement it directly out of the box. I am really confused about all the implementations** I have seen around the forum so an “official” Corona SDK implementation of OOP is a great news for me newbie!

Can’t wait!

Mo

** Unfortunately there is a lot of description of OOP implementation but very little tutorial or even better a full game sample using OOP that I am aware of. I particularly LOVE “ardentKid” tutorials about OOP. I just wish one day he can share a full sample app using it ;) 

I haven’t seen anything that suggests there is a Corona SDK implementation of OOP.  As far as I know you have to use one of the Lua styles out there.  Corona does only support an older version of Lua but there is still a lot of options.

Hi cspense, I have notice this link:

http://docs.coronalabs.com/daily/api/type/CoronaPrototype/initialize.html

Which gives the following example in the API doc there:

local MyClass = CoronaPrototype:newClass( “MyClass” )

function MyClass:initialize()
– custom init
self.foo = “bar”
return self
end

local instance = MyClass:new()
print( instance.foo )

Don’t you think this means that Corona is about to introduce their own OOP implementation (which will be a GREAT news!)?

Mo

That is for file objects, not OOP.

Are you sure? Why file objects (what a heck a file object is anyway?)  would need this type of things? Oh man you destroyed my dream with one sentence…LOL

Thanks cpsence

Mo

You might be right, but take a look at this:

http://docs.coronalabs.com/daily/api/type/File/index.html