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 » Tue Nov 25, 2008 7:23 am

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: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post by rude » Tue Nov 25, 2008 10:41 am

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 » Tue Nov 25, 2008 11:26 am

Lua as in not LOVE. Using the 5.1.4 command line interpreter to be exact.

User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post by rude » Tue Nov 25, 2008 11:48 am

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 » Tue Nov 25, 2008 9:00 pm

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 » Tue Nov 25, 2008 10:50 pm

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 » Wed Nov 26, 2008 5:28 am

If you're working with modules written in lua maybe you could try dofile (with the extension).

User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: require"module" behaviour

Post by rude » Wed Nov 26, 2008 10:40 am

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 » Sat Dec 06, 2008 4:18 pm

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: darkfrei and 67 guests