Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Frog

Pages: 1 2 [3]
31
Lua / Re: Add function to the gc class
« on: September 02, 2011, 12:56:55 pm »
Good ideas in this topic !

However, I should point out that using platform.gc() is discouraged, and is generally a bad idea.
(multiple reasons like the fact that it's not working the exact same way as the 'normal' gc, and for future compatibility matters... ;)  )

Somehow I overlooked your post... Anyways, isn't it true that the usage of platform.gc() in jimbauwens' example is no bad practice, since getmetatables is just a reference to the original metatable shared by all gc objects? I mean, you do use the passed gc in the on.paint() function, so that shouldn't give unexpected results?

Don't you agree that this way looks like a better method for a GUI library?

32
Lua / Re: Add function to the gc class
« on: September 02, 2011, 12:30:06 pm »
Thanks a lot, that's works like a charm! I need to improve my understanding of metatables though...

33
Lua / Re: Add function to the gc class
« on: September 02, 2011, 12:00:09 pm »
I know a separate function is possible, but I think it's way cleaner to make it part of the actual gc, so that the drawButton() method sits prettily next to the drawRect() method. It sounds way more logical to me.  ;)

The latter is exactly what I'm trying to achieve, but that's unfortunately not possible using your code...

34
Lua / Re: Add function to the gc class
« on: September 02, 2011, 11:46:35 am »
Thanks for your answer! That's not exactly what I mean though. I'm trying to add a new method to the gc, so that I can (for example) call gc:drawButton(). In other languages I would extend/subclass the gc class, but I'm not sure how to do that in TI-Lua. At first I thought I should do newGC = class(gc), but that didn't work, just like defining the function: function gc:drawButton(). How can I do this?

35
Lua / Add function to the gc class
« on: September 02, 2011, 11:25:19 am »
Hi everyone! I've been following this forum for quite some time now, but never actually posted something. I guess this is the first time: I've got a question...  :)

I'm trying to add methods and properties to the default gc class. I know that in "normal" lua you can just do something like this: function table.method(). So I tried the following:

Code: [Select]
function gc:method(x, y, width, height)
self:drawRect(x, y, width, height)
end

This didn't work though. I also tried to create a new class called screen that inherits from gc, but that didn't work either. Finally I tried "screen = gc:begin()", but that was no solution as well.

So my question is: how can I add my own method to the default gc class? Thanks! :)

Pages: 1 2 [3]