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 »

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: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: How to separate concerns?

Post by grump »

This is a good starting point.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How to separate concerns?

Post by erasio »

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.
hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Re: How to separate concerns?

Post by hamberge »

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: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: How to separate concerns?

Post by TC1061 »

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: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to separate concerns?

Post by zorg »

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 »

zorg wrote: Tue Oct 17, 2017 7:08 pmIt'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: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to separate concerns?

Post by zorg »

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: Google [Bot] and 63 guests