Page 1 of 1
require"module" behaviour
Posted: Tue Nov 25, 2008 7:23 am
by boypink
I have a feeling LOVE has changed how package loading works. Unlike Lua it requires the filename with an extension. As i move my code to and from LOVE and Lua environments I keep having to change my code.
In LOVE, require"module" fails to load module.lua
In Lua, require"module.lua" fails to load module.lua
Re: require"module" behaviour
Posted: Tue Nov 25, 2008 10:41 am
by rude
What do you mean "in Lua"?
Re: require"module" behaviour
Posted: Tue Nov 25, 2008 11:26 am
by boypink
Lua as in not LOVE. Using the 5.1.4 command line interpreter to be exact.
Re: require"module" behaviour
Posted: Tue Nov 25, 2008 11:48 am
by rude
I have only added a function to package.loaders which uses love.filesystem to find the file you're looking for. The standard package loaders still have precedence, so if require"module" fails, it's because Lua can't find the file ...
Re: require"module" behaviour
Posted: Tue Nov 25, 2008 9:00 pm
by boypink
Well maybe LOVE's package loader is broke. Or, the embedded Lua in love is broke.
require"module" is supposed to work.
Re: require"module" behaviour
Posted: Tue Nov 25, 2008 10:50 pm
by boypink
Take this folder structure
Code: Select all
\temp
\main.lua (contains require"module" line)
\module.lua
From my windows desktop dragging the folder temp onto love shortcut fails.
From the DOS shell specifying the folder name fails
> love.exe temp
but this works
> cd temp
> love.exe .
In all cases above using the filename extension will work, except in vanilla lua.
I can see the issue might have something to do with the current working directory. But that doesnt explain when using the extension why it does work.
In any case theres a workaround and ill change my workflow.
Thanks.
Re: require"module" behaviour
Posted: Wed Nov 26, 2008 5:28 am
by subrime
If you're working with modules written in lua maybe you could try dofile (with the extension).
Re: require"module" behaviour
Posted: Wed Nov 26, 2008 10:40 am
by rude
Nothing is changed or broke, the added function to package.loaders just doesn't understand extension-less filenames.
Added to task list.
Re: require"module" behaviour
Posted: Sat Dec 06, 2008 4:18 pm
by surtic
Would it be possible to also return something from the module, if it returns something?
For example:
Code: Select all
-- xyz.lua ------
local val = "hello"
return val
-- main.lua -----
local val = love.filesystem.require "xyz.lua"
-- val is now nil, should be "hello"
The standard 'require' function does return the value.