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?
How to separate concerns?
Re: How to separate concerns?
This is a good starting point.
Re: How to separate concerns?
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.
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.
Re: How to separate concerns?
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.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to separate concerns?
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 True 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.
Re: How to separate concerns?
'require' is not a reserved keyword.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.1The 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
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to separate concerns?
Whoops, that's what i get for not reading what i copy :p
Me and my stuff True 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.
Who is online
Users browsing this forum: Google [Bot] and 3 guests