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 .
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Thu Oct 08, 2009 8:42 pm
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!
When I write def I mean function .
F687/s
Prole
Posts: 15 Joined: Wed May 20, 2009 8:29 pm
Location: Blowin' Green, O'Hi-o
Contact:
Post
by F687/s » Thu Oct 08, 2009 9:20 pm
"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.
osgeld
Party member
Posts: 303 Joined: Sun Nov 23, 2008 10:13 pm
Post
by osgeld » Thu Oct 08, 2009 10:44 pm
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
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Fri Oct 09, 2009 5:49 am
Like love.filesystem.require
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Fri Oct 09, 2009 3:41 pm
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!
When I write def I mean function .
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Fri Oct 09, 2009 4:00 pm
Yes, you can use module, and require like this:
Tenoch
Citizen
Posts: 76 Joined: Mon Jul 21, 2008 7:49 am
Post
by Tenoch » Fri Oct 09, 2009 9:53 pm
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.
)
"When in doubt, use brute force." Ken Thompson
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sat Oct 10, 2009 6:49 am
Ask rude, I have asked him the same question before.
rude
Administrator
Posts: 1052 Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway
Post
by rude » Sun Oct 11, 2009 7:59 am
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".
Tenoch
Citizen
Posts: 76 Joined: Mon Jul 21, 2008 7:49 am
Post
by Tenoch » Sun Oct 11, 2009 9:02 am
Awesome!
/me happy
"When in doubt, use brute force." Ken Thompson
Users browsing this forum: Ahrefs [Bot] , Google [Bot] and 3 guests