Using Penlight (or other modules) with Corona

How do you incorporate external libraries Corona? I am attempting to use the excellent Penlight library, and have had little success bundling it with my app.

Here is what has failed to work for me so far. Any advice would be greatly appreciated.


My first attempt to include Penlight involved including the full source in its own folder, and modifying package.path to find the Lua files. Sadly, this approach failed.

One of the devs in #corona mentioned that Corona’s loader does not recognize modifications to package.path, a comment that conflicts with the require() documentation:

Otherwise require searches for a Lua loader using the path stored in [package.path][api.library.package.path].

My second attempted involved a more direct require(‘path.to.file’) approach. While this loads the initial Penlight module, it then fails to load the related Penlight dependencies.


What have other people done when bundling an external library into a Corona app? How should one go about doing this?

Not all pure lua libraries will work with Corona SDK for various reasons. But looking at their sample apps you would just drop the “pl” folder into your projects then you can do:

require(“pl.module”) where module is one of their modules.  I did see where they just did a require(“pl”) but I dont’ see a pl.lua file anywhere.

Dropping Penlight’s “lua/pl” folder into a “pl” folder in my project worked.

Since LuaRocks doesn’t bundle libraries with a project, are there any plans to incorporate a package manager into Corona in the mold of npm, bundler/rubygems, or bower?

I’ve not heard any plans to do package management for Lua.  It would likely be a pretty low priority item since most Lua modules are pretty much drop in.

Rob

Not all pure lua libraries will work with Corona SDK for various reasons. But looking at their sample apps you would just drop the “pl” folder into your projects then you can do:

require(“pl.module”) where module is one of their modules.  I did see where they just did a require(“pl”) but I dont’ see a pl.lua file anywhere.

Dropping Penlight’s “lua/pl” folder into a “pl” folder in my project worked.

Since LuaRocks doesn’t bundle libraries with a project, are there any plans to incorporate a package manager into Corona in the mold of npm, bundler/rubygems, or bower?

I’ve not heard any plans to do package management for Lua.  It would likely be a pretty low priority item since most Lua modules are pretty much drop in.

Rob

i think being able to structure libraries as you wish is a normal expectation for any “real” development project.

if Corona SDK fully supported package.path then all of this wouldn’t be an issue. after all, package.path IS a core part of Lua. (and it as OP stated, it is in the Corona documentation)

(note, package.path seemed to work on Simulator, but not on Android).

awhile ago i had a custom method which would allow my framework modules to figure out where they were on the filesystem if the root was changed. later i realized that i should be using package.path, but that’s when i got bitten by the issue surrounding it. now i’m currently re-working a hack for the main require() method, … which i really don’t want to do, only because it deals with the loading process for everything.

dmc

i think being able to structure libraries as you wish is a normal expectation for any “real” development project.

if Corona SDK fully supported package.path then all of this wouldn’t be an issue. after all, package.path IS a core part of Lua. (and it as OP stated, it is in the Corona documentation)

(note, package.path seemed to work on Simulator, but not on Android).

awhile ago i had a custom method which would allow my framework modules to figure out where they were on the filesystem if the root was changed. later i realized that i should be using package.path, but that’s when i got bitten by the issue surrounding it. now i’m currently re-working a hack for the main require() method, … which i really don’t want to do, only because it deals with the loading process for everything.

dmc