How to separate concerns?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
cfazzini
Prole
Posts: 3
Joined: Sat Sep 16, 2017 12:14 pm

How to separate concerns?

Post by cfazzini » Sun Sep 17, 2017 11:03 am

Lately, I've been following this tutorial on Youtube. Everything was created in a single file called main.lua

There were things like player and enemy that seemed like they could have been moved out of main.lua.

I come from Ruby, and I like the fact that I can encapsulate logic into classes. Is there a pattern in love2d/Lua I should be looking at?

grump
Party member
Posts: 200
Joined: Sat Jul 22, 2017 7:43 pm

Re: How to separate concerns?

Post by grump » Sun Sep 17, 2017 12:12 pm

This is a good starting point.

User avatar
erasio
Citizen
Posts: 91
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How to separate concerns?

Post by erasio » Sun Sep 17, 2017 3:28 pm

Short answer: Yes. You usually do though the tutorial probably didn't for simplicitys sake.

You can load any lua file or lua binding dlls with the "require" keyword.

If you just wanna include some code you can assume it's just appended to your main.lua file. Actual modules are written slightly differently. You can take a look at the libraries on the wiki and check out how they did it.

anneroberts
Prole
Posts: 1
Joined: Thu Sep 28, 2017 4:27 am

Re: How to separate concerns?

Post by anneroberts » Thu Sep 28, 2017 4:31 am

Programming dialects can isolate worries into objects, and structural outline designs like MVC or MVP can isolate content from introduction and the information handling (demonstrate) from content. Administration situated outline can isolate worries into administrations.

hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Re: How to separate concerns?

Post by hamberge » Fri Sep 29, 2017 2:28 pm

It's nice to have one class-like table per file and to load that table into another file via require. Each required file can return its created table. One nice thing in lua is that if you require the same file in multiple different files, it returns a reference to the same table.

User avatar
TC1061
Prole
Posts: 28
Joined: Sat Oct 14, 2017 3:50 pm

Re: How to separate concerns?

Post by TC1061 » Tue Oct 17, 2017 4:01 pm

erasio wrote:
Sun Sep 17, 2017 3:28 pm
You can load any lua file or lua binding dlls with the "require" keyword.
Don't lie!!! "require" isn't keyword! It's function!

User avatar
zorg
Party member
Posts: 1913
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to separate concerns?

Post by zorg » Tue Oct 17, 2017 7:08 pm

TC1061 wrote:
Tue Oct 17, 2017 4:01 pm
erasio wrote:
Sun Sep 17, 2017 3:28 pm
You can load any lua file or lua binding dlls with the "require" keyword.
Don't lie!!! "require" isn't keyword! It's function!
It's also a keyword. See the manual: https://www.lua.org/manual/5.1/manual.html#2.1
The following keywords are reserved and cannot be used as names:
and break do else elseif
end false for function if
in local nil not or
repeat return then true until while
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: How to separate concerns?

Post by Azhukar » Wed Oct 18, 2017 12:06 am

zorg wrote:
Tue Oct 17, 2017 7:08 pm
It's also a keyword. See the manual: https://www.lua.org/manual/5.1/manual.html#2.1
The following keywords are reserved and cannot be used as names:
and break do else elseif
end false for function if
in local nil not or
repeat return then true until while
'require' is not a reserved keyword.

User avatar
zorg
Party member
Posts: 1913
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to separate concerns?

Post by zorg » Wed Oct 18, 2017 2:21 am

Azhukar wrote:
Wed Oct 18, 2017 12:06 am
'require' is not a reserved keyword.
Whoops, that's what i get for not reading what i copy :p
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests