1

I am using Embarcadero C++Builder 10.1 32 bit on a Windows 7 64 bit computer. I am compiling everything with the CB10.1 32 bit free version of the Embarcadero IDE. I have compiled lua 5.3.5 to a dll. Then I compiled lua.c into a DOS executable lua.exe (using the lua dll) and it appears to run correctly. I complied luasocket 3.0rc1 to 2 dll's (socket and mime).

The luasocket scripts (ltn12.lua, mbox.lua, mime.lua, and socket.lua) are placed in the 'lua' folder. The remaining luasocket scripts ('ftp.lua', 'headers.lua', 'http.lua', 'smtp.lua', 'tp.lua' and 'url.lua') are placed in the 'socket folder. 'socket.dll' is renamed 'core.dll' and placed in the 'socket' folder. 'mime.dll' is renamed 'core.dll' and placed in the 'mime' folder.

I run lua from a DOS prompt using my compiled lua.c + dll. I can make http/ftp/smtp requests correctly. lua seems to be able to correctly find all of the luasocket core.dll and *.lua scripts.

But when I request a web page which uses https, get a module not found error when lua tries to load 'https.lua'.

So I am trying to compile and install luaSec 0.8 and OpenSSL 1.0.2s.

I want to compile luaSec to a WIN32 dll. I am able to do this. I created a new 'options.h' using 'options.lua' as required. Using a DLL dependency program (Dependency Walker 2.2), I see four exported functions from the 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. 'https.lua' from the luaSec distribution is placed in the 'ssl' folder and 'ssl.lua' is placed in the 'lua' folder.

Then:

My lua script requires luasocket:

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

luasocket (in http.lua) requires luaSec:

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

Then luaSec (in https.lua) requires:

local ssl    = require("ssl")

Then luaSec (in ssl.lua) requires:

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. The second require of 'ssl.context' fails with "module 'ssl.context' not found".

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.

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. Maybe the lua require() function just does not support more than one exported function per dll.

I can't find any guidance on this anywhere.

2
  • 1
    Rename/move ssl/core.dll to plain ssl.dll.
    – siffiejoe
    Jun 14, 2019 at 23:59
  • 1
    As suggested by @siffiejoe and Paul Kulchenko renaming and moving the dll enabled the https protocol to work. Thanks. Jun 15, 2019 at 3:30

1 Answer 1

3

As @siffiejoe suggested, don't put the DLL into ssl\core.dll, but instead make it available as 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. This breaks for the three other calls. To resolve this, just make it available as ssl.dll.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.