我在 Windows 7 64 位计算机上使用 Embarcadero C++Builder 10.1 32 位。我正在使用 Embarcadero IDE 的 CB10.1 32 位免费版本编译所有内容。我已经将 lua 5.3.5 编译成一个 dll。然后我将 lua.c 编译成一个 DOS 可执行文件 lua.exe(使用 lua dll)并且它似乎可以正确运行。我将 luasocket 3.0rc1 编译为 2 个 dll(套接字和 mime)。
luasocket 脚本(ltn12.lua、mbox.lua、mime.lua 和 socket.lua)位于“lua”文件夹中。其余的 luasocket 脚本('ftp.lua'、'headers.lua'、'http.lua'、'smtp.lua'、'tp.lua' 和 'url.lua')放在 'socket 文件夹中。 “socket.dll”重命名为“core.dll”并放置在“socket”文件夹中。 'mime.dll' 重命名为 'core.dll' 并放置在 'mime' 文件夹中。
我使用我编译的 lua.c + dll 从 DOS 提示符运行 lua。我可以正确地发出 http/ftp/smtp 请求。 lua 似乎能够正确找到所有 luasocket core.dll 和 *.lua 脚本。
但是当我请求一个使用 https 的网页时,当 lua 尝试加载“https.lua”时出现模块未找到错误。
所以我正在尝试编译和安装 luaSec 0.8 和 OpenSSL 1.0.2s。
我想将 luaSec 编译成 WIN32 dll。我能够做到这一点。我根据需要使用“options.lua”创建了一个新的“options.h”。使用 DLL 依赖程序 (Dependency Walker 2.2),我从 dll 中看到四个导出函数:
luaopen_ssl_config
luaopen_ssl_context
luaopen_ssl_core
luaopen_ssl_x509
dll 重命名为 core.dll 并放置在“ssl”文件夹中。 luaSec 发行版中的“https.lua”位于“ssl”文件夹中,“ssl.lua”位于“lua”文件夹中。
然后:
我的 lua 脚本需要 luasocket:
local url = require("socket.url")
local http = require("socket.http")
luasocket(在 http.lua 中)需要 luaSec:
local https = assert(require("ssl.https"), 'LuaSocket: LuaSec not found')
然后 luaSec(在 https.lua 中)要求:
local ssl = require("ssl")
然后 luaSec(在 ssl.lua 中)要求:
local core = require("ssl.core")
local context = require("ssl.context")
local x509 = require("ssl.x509")
local config = require("ssl.config")
“ssl.core”的第一个要求有效。 'ssl.context' 的第二个 require 失败并显示“找不到模块 'ssl.context'”。
如果我将 luaSec 编译成四个 dll(core.dll、context.dll、x509.dll 和 config.dll),这样每个 dll 只有一个导出函数并且该函数名称与 require 语句匹配,则 https 请求有效。
我不清楚 lua 应该如何查看 luaopen_ssl_x509、luaopen_ssl_context 和 luaopen_ssl_config 的“core.dll”内部。也许 lua require() 函数不支持每个 dll 多个导出函数。
我在任何地方都找不到这方面的任何指导。
最佳答案
正如@siffiejoe 所建议的,不要将 DLL 放入 ssl\core.dll
,而是将其作为 ssl.dll
提供。第一个 require
调用是偶然的,因为当你需要 ssl.core
时,Lua 将它映射到 ssl\core
(作为尝试之一),它将 ....\?.dll
掩码映射到 package.cpath
变量到 ....\ssl\core.dll
然后在里面找到并调用luaopen_ssl_core
。这会中断其他三个调用。要解决此问题,只需将其作为 ssl.dll 提供即可。
关于c++ - lua 5.3.5 + luasocket 3.0-rc1 + luasec 0.8 : WIN32 DLL with multiple luaopen_xxx_xxx exported function names,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56606041/