lua 5.3.5 + luasocket 3.0-rc1 + luasec 0.8 : 具有多个luaopen_xxx

lua 5.3.5 + luasocket 3.0-rc1 + luasec 0.8 : WIN32 DLL with multiple luaopen_xxx_xxx exported function names

本文关键字:xxx luaopen 0-rc1 luasocket luasec lua      更新时间:2023-10-16

我在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(socket和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文件夹'中。"套接字.dll"更名为"核心.dll"并放置在"套接字"文件夹中。"MIME.dll"更名为"Core.dll"并放置在"MIME"文件夹中。

我使用我编译的lua.c + dll从DOS提示符运行lua。我可以正确地发出http/ftp/smtp请求。Lua似乎能够正确找到所有的Luasocket核心.dll和*.lua脚本。

但是当我请求一个使用 https 的网页时,当 lua 尝试加载"https.lua"时,会出现一个模块未找到错误。

所以我正在尝试编译和安装 luaSec 0.8 和 OpenSSL 1.0.2s。

我想将luaSec编译为WIN32 dll。我能够做到这一点。我根据需要使用"选项.lua创建了一个新的"选项.h"。使用 DLL 依赖程序(依赖 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"的第二个要求失败,并显示"找不到模块'ssl.context'"。

如果我将luaSec编译成四个dll(核心.dll,上下文.dll,x509.dll和config.dll),使得每个dll只有一个导出的函数并且函数名称与require语句匹配,https请求就可以工作。

我不清楚lua如何看待"核心.dll"内部的luaopen_ssl_x509,luaopen_ssl_context和luaopen_ssl_config。也许 lua require() 函数只是不支持每个 dll 导出多个函数。

我在任何地方都找不到任何指导。

> 正如@siffiejoe建议的那样,不要将 DLL 放入sslcore.dll中,而是将其作为ssl.dll提供。第一个require调用是偶然的,因为当你需要ssl.core时,Lua 将其映射到sslcore(作为尝试之一),这会将package.cpath变量中的掩码映射到....sslcore.dll....?.dll然后在其中查找并调用luaopen_ssl_core。对于其他三个调用,这将中断。要解决此问题,只需将其作为 ssl.dll 提供即可。