classes in Lua???

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Tabasco
Citizen
Posts: 72
Joined: Tue Dec 02, 2008 5:04 pm

Re: classes in Lua???

Post by Tabasco »

You shouldn't actually have to recurse anything. When you do something like 'bnvar = Button.new()', you're making an instance of Button. The values you initialize in Button.new are private to bnvar but bnvar has been hooked up to Button (via metatable) so if you have something like Button:Draw() or Button:SetText(), you can execute those functions for bnvar like so: 'bnvar:SetText(mytext)'.

The Button:SetText function might look like this:

Code: Select all

function Button:SetText(newtext)
   self.text = newtext;
end
Feel free to take a look at the gui.lua module in Militia Defense, or even the units in gamedata.lua. It can get pretty nasty as I get a pretty lazy attitude when I'm working in lua, but the class concept and implementation should be sound.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: classes in Lua???

Post by bartbes »

If anyone's still interested in my classes system, you can now find it on the wiki (the one in this thread creates an infinite loop, I shouldn't update without testing).
Link: http://love2d.org/wiki/index.php?title= ... ass_System
User avatar
mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

Re: classes in Lua???

Post by mikembley »

Wow, Just when i thought there couldnt possibly be any more LÖVE puns, SECS really does take the biscuit!

Thanks for the very useful resource, and now its been imortalized in the wiki so i now know where to find it each time i forget how classes work

You serve to be a very helpful person bartbes +100 LÖVE points
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: classes in Lua???

Post by bartbes »

No problem. Appleide's talking about making it support multiple inheritance etc, but I wonder if I can still call it SECS then.. Maybe I should create two version, the basic one and the advanced one. (well, you might also argue I call it simple because it is trivial to use)
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests