0 Members and 2 Guests are viewing this topic.
function gc:method(x, y, width, height) self:drawRect(x, y, width, height)end
function on.paint(gc)method(gc)endfunction method(gc)[...]end
function on.paint(gc)gc2=gcendfunction method()gc2:drawString(...end
function on.paint(gc) method(gc) --is called in on.paint and is passed the gc varendfunction method(gc) gc:drawRect(...) --note the gc:end
gc:method(gc) --pass the gc variable --Do stuff here
gc = getmetatable(platform.gc())function gc:test() self:setColorRGB(0,0,0) self:fillRect(10,10,10,10)endfunction on.paint(gc) gc:test()end
function on.paint(gc) gc2 = getmetatable(gc) function gc2:method(x, y, height, width) self:setColorRGB(0,0,0) self:fillRect(x, y, height, width) end--more methods to define here function on.paint(gc) --Your normal on.paint(gc) goes in here gc:method(10,10,10,10) endend
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... )
Quote from: adriweb on September 02, 2011, 12:26:06 pmGood 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?
local gc=platform.gc()gc:begin()on.paint(gc)gc:finish()
Would this work?It would use the normal gc to define all the methods the first time on.paint is called then when it is done it would redefine itself.
Quote from: Frog on September 02, 2011, 12:56:55 pmQuote from: adriweb on September 02, 2011, 12:26:06 pmGood 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?platform.gc() is a constructor of a new independant gc object.What does the TINspire framework is : Code: [Select]local gc=platform.gc()gc:begin()on.paint(gc)gc:finish()What does that mean ? On each screen refresh, it recreate an independant gc object that has a different reference.And since it is a different object, using methods such as setFont/setColor won't change gc, but your new object you define each time you use platform.gc.If you want to store this gc in on.paint(), it won't be drawn as it, since it has a different reference/addressIn Jim method, you define, yes, one time a new object, but you pick up its meta table. It is not the same. Each gc object has the same metatable, but not the same properties.