简体   繁体   English

Lua 5.3认为socket.lua在实际存在的目录中不存在

[英]Lua 5.3 thinks socket.lua doesn't exist in a directory where it actually does exist

Here's a screenshot: https://drive.google.com/open?id=0B4Dqo44FM648VTVKVzBKSERldGc 这是屏幕截图: https : //drive.google.com/open?id=0B4Dqo44FM648VTVKVzBKSERldGc

I would like to have fun contributing to the development of an open source game but this problem is preventing me from doing this. 我想为开源游戏的开发做出贡献,但是这个问题使我无法这样做。

My LuaRocks install is configured for Lua 5.3 and is set to use MinGW's build tools. 我的LuaRocks安装已针对Lua 5.3配置,并设置为使用MinGW的构建工具。 My OS is Windows 10 64 bit. 我的操作系统是Windows 10 64位。

My Lua 5.3.2 binaries were provided by this website (lua-5.3.2_Win64_bin.zip). 我的Lua 5.3.2二进制文件由网站提供(lua-5.3.2_Win64_bin.zip)。

If you have an idea for a possible cause please post it. 如果您有可能的原因的想法,请发布它。

You have to resolve environment variables manually: 您必须手动解析环境变量:

os.getenv (varname) os.getenv变量名

Returns the value of the process environment variable varname, or nil if the variable is not defined. 返回流程环境变量varname的值;如果未定义该变量,则返回nil。

So, in your case you need to obtain the %APPDATA% path first: 因此,您需要先获取%APPDATA%路径:

os.getenv("APPDATA")

Returns: C:\\Users\\USERNAME\\AppData\\Roaming 返回值:C:\\ Users \\ USERNAME \\ AppData \\ Roaming

When searching for packages to load, Lua uses a pre-defined list of folders to search in. This list is defined in package.path which is a semicolon-delimited (;) string. 当搜索要加载的软件包时,Lua使用预定义的文件夹列表进行搜索。此列表在package.path中定义,它是一个以分号分隔(;)的字符串。 To add a new folder, you must append it's path to package.path : 要添加新文件夹,必须将其路径附加到package.path

package.path = package.path .. ";" .. NEWFOLDER .. "\\?.lua"

Finally, your complete solution is this: 最后,完整的解决方案是这样的:

package.path = package.path .. ";" .. os.getenv("APPDATA") .. "\\luarocks\\share\\lua\\5.3\\?.lua"
local s = require("socket")

“ Lua不会在package.path中扩展环境变量引用,因此%APPDATA%将不起作用。您需要真实的路径。LuaRocks安装脚本应该说:“请注意,上述路径中的%APPDATA%元素是特定于用户,并且必须用其实际值替换。”-siffiejoe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM