Actually @techdojo has fallen foul of that error many many times )
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Come on guys, is there any need to fill up this thread with nonsense? Makes it a pain following important threads when you get messages every few minutes that are nothing to do with it or, actually, much to do with anything in particular other than increasing post counts
@scouser - I see your still hanging around the forums when there's products to develop.., err hang on a minute - D'oh!
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@atilim When opengl 2.0 arrives will we have z depth?
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
There you go - someone always has to bring the conversation back on track
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@Mells you, for example, can add a method (or change it some how differently) to Object class, and this method (or other change) will appear in any class that was created used Core.class function (so basically in any class)
I see. It's hard for me to see how useful it could really be without specific examples. What is possible now that was not possible before? If it was added, that means that there was a specific need for it and I'd like to understand better.
@atilim when is it useful, can you provide an example?
For example, let's say you want to add a method to every class, that would retrieve a class name, so you could compare:
--if specific instance is of specific classif inst:getClassName()== SomeClass then--do your stuffend
Without root Object, you would have to go through every root class (that does not have someone they inherited from) and add this method to them. It would be like: EventDispatcher, TextureBase, FontBase, Application, Sound, SoundChannel, etc.
But if you have one root Object where everyone inherits from it (internally), you may add this method only to the root Object and all other classes will have this method automatically
@Mells, I suppose since it was my proposal, I ought to give an example or two.
Well, it's exactly like @ar2rsawseen says, it gives you the opportunity to add methods that can be actioned on any object in the system. There shouldn't be any performance penalty unless you actually add code that causes one.
So, for example, you might want a (C++ style) "destructor" to be called when any object is GC'ed. You can do this with:
function Object:enableDestructor()
self._proxy = newproxy(true)getmetatable(self._proxy).__gc =function() self:_destroy()endendfunction Object:_destroy()end
MyClass=Core.class(Object)function MyClass:postInit()
self:enableDestructor()endfunction MyClass:_destroy()print("That's the last you'll see of me")end
You might want to add other methods like getClassName(), to answer the string class name of a particular object.
function getClassName(class)-- Answers a string name for a supplied class object.-- Note, this involves a sequential search through the global table so is -- not particularly fast.--for k,v inpairs(_G)doif v==class thenreturn k
endendendfunction Object:getClass()returngetmetatable(self)endfunction Object:getClassName()return getClassName(self:getClass())end
You may have seen in another thread that you can use these ideas to implement a system that helps track memory leaks:
I think the good thing about it is that it opens up possibilities that are impossible without it (that destructor idea for example) but there is no performance penalty if you don't use it, so what's not to like?
@Mells, that thread is perhaps a little confusing since it sort of morphs through a range of different ideas as it progresses.
For a "correct" implementation of isKindOf() one really needs to wind up the superclass chain of the object being tested to see if is a subclass of the supplied class. Unfortunately, @atilim, told me in a PM that the latest release doesn't correctly add a .super field to the builtin classes (like Sprite etc). This means that a real isKindOf() will not yet work consistently.
However, most uses of such a test can make do with a direct class comparison. Lets call this isA(). You can implement this like:
function Object:isA(class)return self:getClass()==class
end
Comments
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
by the way anyone knows about the issue of smiley )
edit :- god knows why but it is working now
Likes: hgvyas123, techdojo
: ) ) and : - ) )
without space
Sorry for being grumpy.
Likes: atilim
Likes: atilim, techdojo, hgvyas123
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
:-O
Likes: hgvyas123
https://deluxepixel.com
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: SinisterSoft
Dislikes: AhBadiane
Likes: ar2rsawseen, hgvyas123, SinisterSoft
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
)
What is possible now that was not possible before?
If it was added, that means that there was a specific need for it and I'd like to understand better.
@atilim when is it useful, can you provide an example?
For example, let's say you want to add a method to every class, that would retrieve a class name, so you could compare:
But if you have one root Object where everyone inherits from it (internally), you may add this method only to the root Object and all other classes will have this method automatically
Likes: Mells
Well, it's exactly like @ar2rsawseen says, it gives you the opportunity to add methods that can be actioned on any object in the system. There shouldn't be any performance penalty unless you actually add code that causes one.
So, for example, you might want a (C++ style) "destructor" to be called when any object is GC'ed. You can do this with:
http://giderosmobile.com/forum/discussion/2645/help-with-memory-leak#Item_13
I think the good thing about it is that it opens up possibilities that are impossible without it (that destructor idea for example) but there is no performance penalty if you don't use it, so what's not to like?
best regards
Likes: Mells
I see thank you, that was helpful.
I will need to think more about it and see what I could do with it.
So... I believe it could be a solution to my unanswered question there :
For a "correct" implementation of isKindOf() one really needs to wind up the superclass chain of the object being tested to see if is a subclass of the supplied class. Unfortunately, @atilim, told me in a PM that the latest release doesn't correctly add a .super field to the builtin classes (like Sprite etc). This means that a real isKindOf() will not yet work consistently.
However, most uses of such a test can make do with a direct class comparison. Lets call this isA(). You can implement this like:
thank you very much.