lua中有类似python的virtualenv的东西吗?
所以我可以在沙盒环境中安装所有必需的 lua 模块/rocks。这对测试很有好处,因为我不会弄乱系统范围的 lua 模块或另一个 lua 项目的环境。
luarocks 看起来很有前途,因为它支持 self-contained installation 。但我感兴趣的是,是否有像 virtualenv 这样的工具可以自动创建、维护和切换沙盒环境。
最佳答案
通过设置 LUA_PATH
在 Lua 安装之间切换应该相当简单。环境变量。引用this page来自 Lua 文档:
To determine its path, require first checks the global variable LUA_PATH. If the value of LUA_PATH is a string, that string is the path. Otherwise, require checks the environment variable LUA_PATH.
[...]
The components in a path are separated by semicolons (a character seldom used for file names in most operating systems). For instance, if the path is
?;?.lua;c:\windows\?;/usr/local/lua/?/?.lua
然后调用 require"lili"将尝试打开以下文件:
block 引用>lili
lili.lua
c:\windows\lili
/usr/local/lua/lili/lili.lua
关于Lua相当于virtualenv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4358849/