A loader for the full "package.subpackage" notation.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

A loader for the full "package.subpackage" notation.

Post by pygy »

O HAÏ

Here's a short piece of code that makes require work in LÖVE as it does in Lua for packages and subpackages... With a corny name as usual...

require "pack.subpack"

will look for pack/subpack/init.lua then for pack/subpack.lua in all folders registered using

MLL.addPath("directory name")

It uses a search function copied verbatim from the PiL book, and uses love.filesystem.load() to load the file if it's ever found.

Code: Select all

local MLL = require "MagnaLuvLoader.lua"
MLL.addPath "Library"
require "what.ever.you.want" -- :-D
MagnaLuvLoader.lua
The Magna Luv Loader
(1.42 KiB) Downloaded 130 times
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: A loader for the full "package.subpackage" notation.

Post by Luiji »

Cool idea!
Good bye.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 32 guests