9

I want to add a module path for all of my project in zerobrane. I add following code into the user.lua.

LUA_PATH=LUA_PATH .. ';mypath'  or
package.path=package.path .. ';mypath'

It can't work. how can I do it ?

PS
I don't want to set the package.path at the begin of all the project.

bytefire
  • 4,156
  • 2
  • 27
  • 36
Samuel
  • 5,977
  • 14
  • 55
  • 77

3 Answers3

23

When Lua starts, it initialises package.path and package.cpath with values of LUA_PATH and LUA_CPATH environment variables. Setting up these environment variables will be one clean way to set paths. Appending LUA_PATH's value with a double semi-colon will make Lua append the default path to the specified path.

Using bash on Linux, you can set the paths by adding these lines to the end of ~/.bashrc file. For example:

## final ;; ensure that default path will be appended by Lua
export LUA_PATH="<path-to-add>;;"
export LUA_CPATH="./?.so;/usr/local/lib/lua/5.3/?.so;
                /usr/local/share/lua/5.3/?.so;<path-to-add>"

Hope it helps.

bytefire
  • 4,156
  • 2
  • 27
  • 36
  • I tried setting LUA_PATH and LUA_CPATH through bash.bashrc.local and it is set which I made sure by using echo in terminal. But, my lua scripts still cannot find some modules. Here is my post: https://stackoverflow.com/questions/54865886/modifying-haproxy-lua-library-path – Abrar Hossain Feb 27 '19 at 09:46
0

You can set LUA_PATH and LUA_CPATH before starting ZeroBrane Studio and it should pass those values to all the projects you run or debug from the IDE.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
-4

I add following method into the /opt/zbsstudio/lualibs/mobdebug/mobdebug.lua file.

package.path = package.path .. ';my_path/?/init.lua'
package.cpath = package.cpath .. ';my_path/?.so'

But I'm not sure that's the best way.

Samuel
  • 5,977
  • 14
  • 55
  • 77
  • 4
    If you are not sure why is this an accepted answer? – minerals Apr 13 '17 at 15:43
  • It's not a good idea to edit files which are part of some software. They'll be overwritten next time you upgrade or reinstall the software and you would have to re-apply those changes every time you do that. – David Ferenczy Rogožan Aug 05 '19 at 14:43