0

I'm working on a Lua script which will be hosted by a third party program (some .exe which will call a certain function in my script). In order to implement a functionality I need (make a rest call to a webservice to retrieve certain info) I want to use socket.http.request.

I've first build an example script for the call I wanted to make:

local io = require("io")
local http = require("socket.http")
local ltn12 = require("ltn12")

local data =  "some data")
local response = {}
socket.http.request({
    method = "POST",
    url = "http://localhost:8080/someServce/rest/commands/someCommand",
    headers = {
            ["Content-Type"] = "application/x-www-form-urlencoded",
            ["Content-Length"] = string.len(data)
        },
    source = ltn12.source.string(data),
    sink = ltn12.sink.table(response)
    })
print(table.concat(response))
print("Done")

This works fine. I get the response I expect. Now when I try to do this from the third party host, I first got an error:

 module 'socket.http' not found:
    no field package.preload['socket.http']
    no file '.\socket\http.lua'
    no file 'D:\SomeFolder\lua\socket\http.lua'
    no file 'D:\SomeFolder\lua\socket\http\init.lua'
    no file 'D:\SomeFolder\socket\http.lua'
    no file 'D:\SomeFolder\socket\http\init.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\socket\http.luac'
    no file '.\socket\http.dll'
    no file 'D:\SomeFolder\socket\http.dll'
    no file 'D:\SomeFolder\loadall.dll'
    no file '.\socket.dll'
    no file 'D:\SomeFolder\socket.dll'
    no file 'D:\SomeFolder\loadall.dll'

I've tried copying the socket folder from the LUA folder to the folder the host is executing from (D:\SomeFolder). It then finds the module, but fails to load it with another error:

loop or previous error loading module 'socket.http'

I've also tried moving the require statement outside of the function and making it global. This gives me yet another error:

 module 'socket.core' not found:
    no field package.preload['socket.core']
    no file '.\socket\core.lua'
    no file 'D:\SomeFolder\lua\socket\core.lua'
    no file 'D:\SomeFolder\lua\socket\core\init.lua'
    no file 'D:\SomeFolder\socket\core.lua'
    no file 'D:\SomeFolder\socket\core\init.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\socket\core.luac'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\socket\core.lua'
    no file '.\socket\core.dll'
    no file 'D:\SomeFolder\socket\core.dll'
    no file 'D:\SomeFolder\loadall.dll'
    no file '.\socket.dll'
    no file 'D:\SomeFolder\socket.dll'
    no file 'D:\SomeFolder\loadall.dll'

Then I tried copying the core.dll from socket into the D:\SomeFolder folder and it gave me another error:

error loading module 'socket.core' from file '.\socket\core.dll':
    %1 is not a valid Win32 application.

Now I'm stuck. I think I must be doing something completely wrong, but I can't find any proper description on how to fix issues like this. Can anyone help me out?

4

2 回答 2

2

事实证明,Lua 要寻找的实际路径就是这里的问题。与第三方一起,我们发现如果我们将一组库放入D:\SomeFolder\现在一切都可以正常工作。因此,例如现在有一个 socket.luaD:\SomeFolder\并且那里也有一个套接字和一个 mime forlder。

经验法则似乎是应用程序绑定的lua5.1.dll的位置领先于您要加载的任何模块的位置。

于 2013-09-30T06:51:46.940 回答
1

您可能需要具有以下文件夹结构(相对于您的D:\SomeFolder文件夹):

socket.lua
socket/core.dll
socket/http.lua
socket/url.lua
socket/<any other file from socket folder required by http.lua>

我刚刚测试了这个配置,它对我有用。

循环或以前的错误加载模块“socket.http”

这通常是由socket.httpsocket/http.lua文件本身加载引起的。

于 2013-09-23T16:56:35.473 回答