require"module" behaviour

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.
Post Reply
User avatar
boypink
Prole
Posts: 10
Joined: Sat Nov 15, 2008 5:40 am
Location: Canada

require"module" behaviour

Post 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
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post by rude »

What do you mean "in Lua"?
User avatar
boypink
Prole
Posts: 10
Joined: Sat Nov 15, 2008 5:40 am
Location: Canada

Re: require"module" behaviour

Post by boypink »

Lua as in not LOVE. Using the 5.1.4 command line interpreter to be exact.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post 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 ...
User avatar
boypink
Prole
Posts: 10
Joined: Sat Nov 15, 2008 5:40 am
Location: Canada

Re: require"module" behaviour

Post by boypink »

Well maybe LOVE's package loader is broke. Or, the embedded Lua in love is broke.

require"module" is supposed to work.
User avatar
boypink
Prole
Posts: 10
Joined: Sat Nov 15, 2008 5:40 am
Location: Canada

Re: require"module" behaviour

Post 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.
User avatar
subrime
Citizen
Posts: 76
Joined: Thu Nov 13, 2008 6:18 pm
Location: Australia

Re: require"module" behaviour

Post by subrime »

If you're working with modules written in lua maybe you could try dofile (with the extension).
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post by rude »

Nothing is changed or broke, the added function to package.loaders just doesn't understand extension-less filenames.

Added to task list.
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: require"module" behaviour

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests