Skip to content

best way to require lua files? #727

@emiltin

Description

@emiltin

Recently a number of users have had problems related to the file /profiles/libs/access.lua not being found.

The LUA profiles contain the line:

require("lib/access")

OSRM internally adds two paths where LUA will look for required files: the folder that contains the main lua profile script, and profiles/. (See more about LUA paths at http://lua-users.org/wiki/PackagePath.)

The problem occurs when users run the bins from a different location that the OSRM file, and the profile script is not located in the same folder as the lib/ folder, or you're using a symlink placed outside the OSRM folder.

Curently profiles/lib/access.lua is quite short. So we could choose to replicate the code in all the profiles. But I believe the ability to include other LUA files is very useful and enables splitting out common code to separate files. Maintaining the same code in several locations is very error prone. I also think it would be useful to extract more common code from the existing profiles into files in lib/.

I therefore think the question is how to best enable requiring lua files when the bins/profile/libs are places in separate locations. A few options:

  • Use a custom path when you require the script. I think this is not very portable/practical, since you cannot relocate your lua profile without modifying the require statement, or moving/symlinking the required files.
  • Pass one or more lua search paths to the bin. I believe this is the best solution. It can be implemented rather easily with boost program_options, and can also be used to provide sensible default values, so you don't have to pass anything when things are placed in the default locations.

Thoughts? Are there other good options?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions