Need more Löve for require()...

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
emonk
Prole
Posts: 24
Joined: Tue Aug 12, 2008 11:43 am

Need more Löve for require()...

Post by emonk »

Having fun playing with Love, learning Lua and all those fun things. Been playing around with some basic stuff using a couple of Lua files to organize my thoughts, and it's working out reasonably well... until I pack my project into a .love and run it, when it all falls down.

I figure that the integration of PhysFS with the Lua code isn't quite complete, resulting in some issues with things like require().

So... is there a roadmap for the project showing the status of items like this? Should we start using the SourceForge project tracker, which is currently empty?

I'll start hacking at the source if I get a chance and see what I can figure out, but don't anybody hold their breath :D
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Need more Löve for require()...

Post by Merkoth »

You should use love.filesystem.require() instead of Lua's standard functions. That should do the trick and let you package your game :)
emonk
Prole
Posts: 24
Joined: Tue Aug 12, 2008 11:43 am

Re: Need more Löve for require()...

Post by emonk »

AHA!

Right, that's what I needed to know.

Are there plans to modify the standard Lua functions to work via PhysFS? Should I just assume that most of the io, os and file stuff is going to disappear and therefore should be avoided where possible?
Sarcasm - just one of the services I offer.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Need more Löve for require()...

Post by rude »

Io, os and file will perish ... as for globals such as require(), it hasn't really been discussed yet.
emonk
Prole
Posts: 24
Joined: Tue Aug 12, 2008 11:43 am

Re: Need more Löve for require()...

Post by emonk »

I replaced require with love.filesystem.require, but since I'm in the habit of dropping my extensions when calling include/require and love.filesystem.require expects a full filename, I put the following in top of my main.lua:

Code: Select all

function __require(modname)
	for p in string.gmatch("?;?.lua", "[^;]+") do 
	local res, _ = pcall(function() love.filesystem.require(select(1, string.gsub(p, "\?", modname))); end);
		if res then return true end
	end
	error("require() Could not locate include file '"..modname.."'");
end

Lua_require = require;
require = __require;
Works quite well :D
Sarcasm - just one of the services I offer.
Post Reply

Who is online

Users browsing this forum: No registered users and 213 guests