What module/class structure should I use in this case?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
pancakepalace
Prole
Posts: 40
Joined: Wed Aug 03, 2011 3:13 pm

What module/class structure should I use in this case?

Post by pancakepalace » Thu Aug 25, 2011 2:33 pm

Hi guys,

I'm currently building a drawing library for Love which makes it easy to draw geometric shapes likes arcs, ellipses, isosceles triangles, ovoids, etc... I'm almost done all my basic functions, but I'm wondering how I should structure my code. One thing I realize is that I can't possibly cover all shapes so I'm considering having a core with the basic shape making engines, and the extensions which add funky shapes like stars and so on.

My first idea was to use a simple metatable. Here is the code: https://github.com/xenakis/draft/blob/master/draft.lua

My second idea was to use a simple table. https://github.com/xenakis/draft/blob/m ... rcular.lua

I switch to the second idea when I decided I did not need a constructor that sets up the mode variable. At this point, I'm thinking that he second idea is better for my needs, but I'm not sure. Will I be able to extend a table/class made this way easily if I want to add more shapes later on, or if another user wants to add his own shapes?

Once I figure out the best way to structure this library, I'll finish it up write some docs and give it out to the community.

I'm a Love/Lua beginner, so any help or insight would be greatly appreciated.

Thank you

P.S. Please note that the code libraries I linked to are note tested. I just want insight on how to structure the library. Once I know this, I'll cleanup and test the code.

User avatar
bartbes
Sex machine
Posts: 4944
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: What module/class structure should I use in this case?

Post by bartbes » Thu Aug 25, 2011 2:47 pm

Is this the time to plug Class Commons? I think so.

As for a more in-depth answer, sadly I don't quite understand what you're trying to accomplish, so I can't recommend anything (but class commons :P).
Perhaps you could clarify a bit?

pancakepalace
Prole
Posts: 40
Joined: Wed Aug 03, 2011 3:13 pm

Re: What module/class structure should I use in this case?

Post by pancakepalace » Thu Aug 25, 2011 3:20 pm

Thanks for bartbes, I'll definitely look into it.

What I want to do is very simple. If you take a look at this code, https://github.com/xenakis/draft/blob/m ... rcular.lua notice the first function arc(). This is essentially an engine that makes it easy to draw circular shapes. The functions that follow all use it to draw circles, ellipses, stars, eggs, etc... What I want is a way to make a class containing only the engine arc() (There will also be other engines), then a way to extend this class to add functions that draw shapes like stars. I'm not even sure if I need a 'class', maybe just a table. I don't have any variables to set to default during the constructor. So you would call the functions like this draft.circle, draft.arc, etc... A user should easily be able to add a file with his own functions that use the engines and then call his additions in the same way, perhaps, draft.equilateralTriangle. There's a huge amount of shapes that could be setup using this engine, so I can't possibly have them all in one file.

What I want is the most simple quick way that uses the least dependancies. What I'd love is a simple structure that can be done without any dependencies.

Does that make sense?

I'm also wondering if I have to draw my polygons counter-clockwise if I want to use them with box2D. I think I read that somewhere, but I'm not too sure.

User avatar
genericdave
Citizen
Posts: 53
Joined: Tue Dec 15, 2009 9:08 am

Re: What module/class structure should I use in this case?

Post by genericdave » Thu Aug 25, 2011 10:23 pm

Have you taken a look at the lua users wiki? They have a lot of stuff having to do with different styles and practices. They should have a section on OOP. Go and pick something you like. Honestly, though, libs like middleclass and Bartbes' new class-commons are well worth adding the dependency. There's also that 32 lines of love or something over on the love wiki under libraries. Maybe that's more what you want.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: What module/class structure should I use in this case?

Post by Robin » Fri Aug 26, 2011 4:53 am

You mean 32 lines of madness?

I'd recommend the Class-Commons bartbes plugged earlier.
Help us help you: attach a .love.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests