Page 1 of 1
Modules in Löve
Posted: Thu Oct 08, 2009 8:42 pm
by kikito
Hello fellow lövers!
I'd like to develop something on LÖVE, but I'd be much more comfortable if I was able to split my lua code on several files.
A folder would actually be nice, too.
"Vanilla" LUA offers "require" and "module" functions for organizing your code - what is the nearest equivalent in LÖVE?
Let's imagine that I want to create a package with the following structure:
Code: Select all
main.lua
package/
module1.lua
module2.lua
init.lua
What should I include on each of the 3 lua files above?
Thanks a lot
PS: Avatar!
Re: Modules in Löve
Posted: Thu Oct 08, 2009 9:20 pm
by F687/s
"Vanilla" LUA offers "require" and "module" functions for organizing your code - what is the nearest equivalent in LÖVE?
Well, um...
require() , to tell the truth. In version 0.5.0, you can use
love.filesystem.require() to load external code, but 0.6 just simplifies it down to require. Just place all the includes in your
load() function (or
love.load() for 0.6), and experience the magic of code organization!
Hope that answers your question.
Re: Modules in Löve
Posted: Thu Oct 08, 2009 10:44 pm
by osgeld
ok i have a question
by default core lua likes require differently than one would expect
ie
require("bob.lua") looks in folder bob for *.lua
and
require("bob") loads bob.lua
I havent gotten around to luv 6 and was wondering how this new require function works, is is like core lua or like love.filesystem.require()
spanks
Re: Modules in Löve
Posted: Fri Oct 09, 2009 5:49 am
by bartbes
Like love.filesystem.require
Re: Modules in Löve
Posted: Fri Oct 09, 2009 3:41 pm
by kikito
Hey guys,
Thanks for your input. However, you didn't tell me anything I didn't already know.
What I need are the details. For example:
- What should Iwrite on main.lua? require 'package'? 'package.module1'? or love.filesystem.require something? Should I use
- Can I use "module" on my module files? If so, do I get it to work? Is there a special syntax in LÖVE?
I've tried the "vanilla LUA way"(section 5.3 on
http://www.lua.org/manual/5.1/manual.html) doesn't seem to work on LÖVE.
What am I supposed to write on main.lua, module1.lua and module2.lua?
Thanks and regards!
Re: Modules in Löve
Posted: Fri Oct 09, 2009 4:00 pm
by bartbes
Yes, you can use module, and require like this:
Re: Modules in Löve
Posted: Fri Oct 09, 2009 9:53 pm
by Tenoch
I still don't get why we don't comply totally to the Lua standard and make require() take only the module name, without the .lua
Especially if you use the module() function in it, which iirc uses the name passed to require() to name to module.
(Oh and Lua is capitalized Lua. Not LUA.
)
Re: Modules in Löve
Posted: Sat Oct 10, 2009 6:49 am
by bartbes
Ask rude, I have asked him the same question before.
Re: Modules in Löve
Posted: Sun Oct 11, 2009 7:59 am
by rude
Tenoch wrote:I still don't get why we don't comply totally to the Lua standard and make require() take only the module name [...]
In 0.6.0, you can choose between require("foo.lua"), and require("foo"). You can also do require("foo.bar"), which will expand to "foo/bar.lua".
Re: Modules in Löve
Posted: Sun Oct 11, 2009 9:02 am
by Tenoch
Awesome!
/me happy