简体   繁体   English

lua 5.3.5 + luasocket 3.0-rc1 + luasec 0.8:具有多个 luaopen_xxx_xxx 导出函数名的 WIN32 DLL

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

I am using Embarcadero C++Builder 10.1 32 bit on a Windows 7 64 bit computer.我在 Windows 7 64 位计算机上使用 Embarcadero C++Builder 10.1 32 位。 I am compiling everything with the CB10.1 32 bit free version of the Embarcadero IDE.我正在使用 Embarcadero IDE 的 CB10.1 32 位免费版本编译所有内容。 I have compiled lua 5.3.5 to a dll.我已将 lua 5.3.5 编译为 dll。 Then I compiled lua.c into a DOS executable lua.exe (using the lua dll) and it appears to run correctly.然后我将 lua.c 编译成 DOS 可执行文件 lua.exe(使用 lua dll),它似乎运行正常。 I complied luasocket 3.0rc1 to 2 dll's (socket and mime).我将 luasocket 3.0rc1 编译为 2 个 dll(套接字和 mime)。

The luasocket scripts (ltn12.lua, mbox.lua, mime.lua, and socket.lua) are placed in the 'lua' folder. luasocket 脚本(ltn12.lua、mbox.lua、mime.lua 和 socket.lua)位于“lua”文件夹中。 The remaining luasocket scripts ('ftp.lua', 'headers.lua', 'http.lua', 'smtp.lua', 'tp.lua' and 'url.lua') are placed in the 'socket folder.其余的 luasocket 脚本('ftp.lua'、'headers.lua'、'http.lua'、'smtp.lua'、'tp.lua' 和 'url.lua')放在 'socket 文件夹中。 'socket.dll' is renamed 'core.dll' and placed in the 'socket' folder. 'socket.dll' 被重命名为 'core.dll' 并放置在 'socket' 文件夹中。 'mime.dll' is renamed 'core.dll' and placed in the 'mime' folder. 'mime.dll' 被重命名为 'core.dll' 并放置在 'mime' 文件夹中。

I run lua from a DOS prompt using my compiled lua.c + dll.我使用我编译的 lua.c + dll 从 DOS 提示符运行 lua。 I can make http/ftp/smtp requests correctly.我可以正确地发出 http/ftp/smtp 请求。 lua seems to be able to correctly find all of the luasocket core.dll and *.lua scripts. lua 似乎能够正确找到所有 luasocket core.dll 和 *.lua 脚本。

But when I request a web page which uses https, get a module not found error when lua tries to load 'https.lua'.但是当我请求使用 https 的网页时,当 lua 尝试加载“https.lua”时,会出现未找到模块的错误。

So I am trying to compile and install luaSec 0.8 and OpenSSL 1.0.2s.所以我正在尝试编译和安装 luaSec 0.8 和 OpenSSL 1.0.2s。

I want to compile luaSec to a WIN32 dll.我想将 luaSec 编译为 WIN32 dll。 I am able to do this.我有能力做到这一点。 I created a new 'options.h' using 'options.lua' as required.我根据需要使用“options.lua”创建了一个新的“options.h”。 Using a DLL dependency program (Dependency Walker 2.2), I see four exported functions from the dll:使用 DLL 依赖程序(Dependency Walker 2.2),我看到从 dll 导出的四个函数:

    luaopen_ssl_config
    luaopen_ssl_context
    luaopen_ssl_core
    luaopen_ssl_x509

The dll is renamed to core.dll and placed in the 'ssl' folder. dll 被重命名为 core.dll 并放置在“ssl”文件夹中。 'https.lua' from the luaSec distribution is placed in the 'ssl' folder and 'ssl.lua' is placed in the 'lua' folder. luaSec 发行版中的“https.lua”放在“ssl”文件夹中,“ssl.lua”放在“lua”文件夹中。

Then:然后:

My lua script requires luasocket:我的 lua 脚本需要 luasocket:

local url = require("socket.url")
local http = require("socket.http")

luasocket (in http.lua) requires luaSec: luasocket(在 http.lua 中)需要 luaSec:

local https = assert(require("ssl.https"), 'LuaSocket: LuaSec not found')

Then luaSec (in https.lua) requires:然后 luaSec(在 https.lua 中)需要:

local ssl    = require("ssl")

Then luaSec (in ssl.lua) requires:然后 luaSec(在 ssl.lua 中)需要:

local core    = require("ssl.core")
local context = require("ssl.context")
local x509    = require("ssl.x509")
local config  = require("ssl.config")

The first require of 'ssl.core' works. 'ssl.core' 的第一个要求有效。 The second require of 'ssl.context' fails with "module 'ssl.context' not found". 'ssl.context' 的第二个要求失败,并显示“找不到模块 'ssl.context'”。

If I compile luaSec into four dll's (core.dll, context.dll, x509.dll and config.dll) such that each dll only has one exported function and that function name matches the require statement, the https requests work.如果我将 luaSec 编译成四个 dll(core.dll、context.dll、x509.dll 和 config.dll),这样每个 dll 只有一个导出函数并且该函数名称与 require 语句匹配,则 https 请求工作。

Its not clear to me how lua is expected to look inside the 'core.dll' for luaopen_ssl_x509, luaopen_ssl_context and luaopen_ssl_config.我不清楚 lua 如何查看 luaopen_ssl_x509、luaopen_ssl_context 和 luaopen_ssl_config 的“core.dll”。 Maybe the lua require() function just does not support more than one exported function per dll.也许 lua require() 函数只是不支持每个 dll 多个导出函数。

I can't find any guidance on this anywhere.我在任何地方都找不到这方面的任何指导。

As @siffiejoe suggested, don't put the DLL into ssl\\core.dll , but instead make it available as ssl.dll .正如@siffiejoe 建议的那样,不要将 DLL 放入ssl\\core.dll ,而是将其作为ssl.dll The first require call works by accident, because when you require ssl.core , Lua maps it to ssl\\core (as one of the attempts), which maps ....\\?.dll mask in your package.cpath variable to ....\\ssl\\core.dll and then finds and calls luaopen_ssl_core in it.第一个require调用是偶然的,因为当你需要ssl.core ,Lua 将它映射到ssl\\core (作为尝试之一),它将package.cpath变量中的....\\?.dll掩码映射到....\\ssl\\core.dll然后在其中查找并调用luaopen_ssl_core This breaks for the three other calls.这会中断其他三个调用。 To resolve this, just make it available as ssl.dll.要解决此问题,只需将其作为 ssl.dll 提供即可。

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

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