Mihail Nazarov
Mihail Nazarov

Reputation: 11

Problems with package.path in CoronaSDK

We want to integrate a third-party Lua module (say) foo into our CoronaSDK application.

Main code of this module module is in foo/init.lua, to be required as require 'foo'.

We placed this module into corona/foo:

corona/foo$ ls
  init.lua

In corona/main.lua we have:

package.path = package.path .. ";"
  .. package.path:gsub("?.lua", "?/init.lua")

require 'foo' works in the simulator. However, it does not work on the device:

Lua Runtime Error: lua_pcall failed with status: 2, error message is:
module 'foo' not found:resource (foo.lua) does not exist in
archive
  no field package.preload['foo']
  no file '/var/mobile/Applications/0B609A43-54E8-40E5-9D44-F3C93CC4031E/Appname.app/foo.lua'
  no file '/var/mobile/Applications/0B609A43-54E8-40E5-9D44-F3C93CC4031E/Appname.app/foo.lua'
  no file '/var/mobile/Applications/0B609A43-54E8-40E5-9D44-F3C93CC4031E/Appname.app/foo/init.lua'
  no file '/var/mobile/Applications/0B609A43-54E8-40E5-9D44-F3C93CC4031E/Appname.app/foo/init.lua'
  no file './foo.so'

Strangely enough, require 'foo.init' does work.

Any clues?

Upvotes: 1

Views: 1140

Answers (2)

Joe Huang
Joe Huang

Reputation: 6570

Is your filename

foo.lua or Foo.lua?

it works on simulator for both cases, but in devices, the capital matters.

I had this nightmare (I wonder why my SVN client changed the capital for one of my files... I spent over an hour to find out what went wrong because my module couldn't be found in the device suddenly)

Upvotes: 1

Sam
Sam

Reputation: 21

Try this

package.path = package.path .. ";" .. package.path:gsub("?.lua", "?.init.lua")

path names for lua files called in packages should be done like this:

dir.luafile.lua

rather than dir/luafile.lua

hope that helps

Upvotes: -1

Related Questions