我在windows上的lua5.1中编译了一个c lua扩展dll,它在lua命令行模式下运行良好,但不能在openresty中使用

我在windows上的lua5.1中编译了一个c lua扩展dll,它在lua命令行模式下运行良好,但不能在openresty中使用,dll,lua,openresty,Dll,Lua,Openresty,提供了一个名为lua pack.c的c代码,它是进程十六进制字符串的lua扩展,我需要在openresty中使用它来处理一些网络流 我用lua5.1和Luarock在windows中安装它 我成功地获取了lua-pack.dll。所有测试都在命令行模式下成功运行,如下所示 local bpack, bunpack do local string_pack = string.pack local string_unpack = string.unpack require "

提供了一个名为lua pack.c的c代码,它是进程十六进制字符串的lua扩展,我需要在openresty中使用它来处理一些网络流

我用lua5.1和Luarock在windows中安装它

我成功地获取了lua-pack.dll。所有测试都在命令行模式下成功运行,如下所示

local bpack, bunpack
do
    local string_pack = string.pack
    local string_unpack = string.unpack
    require "lua_pack"
    bpack = string.pack
    bunpack = string.unpack
    -- luacheck: globals string.unpack
    string.unpack = string_unpack
    -- luacheck: globals string.pack
    string.pack = string_pack
end
lua C:\projects\lua pack\lua pack\test.lua

但一旦我将这个lua-pack.dll放入openresty的dir中并使用它,一些异常就会抛出

worker process 24892 exited with code C0000005
我可以在ubuntu中成功编译lua-pack.so(通过makefile编译),它在linux的openresty中正常工作。我试图将这个lua-pack.so复制到windows,但它抛出了一个异常,说这个so不适合windows使用

但是,我注意到,在作者提供的test.lua中,它需要(pack)而不是require(lua_pack)

因此,我将lua-pack.dll重命名为pack.dll,然后出现了另一个异常

lua entry thread aborted: runtime error: error loading module 'pack' from file '.\pack.dll':
我注意到这是一个包。lua在lua rocks窗口,我不知道这是否重要

由作者提供的test.lua如下启动,可以在Windows命令行中运行

require"pack"
bpack=string.pack
bunpack=string.unpack
我的代码在Linux openresty中工作,如下所示

local bpack, bunpack
do
    local string_pack = string.pack
    local string_unpack = string.unpack
    require "lua_pack"
    bpack = string.pack
    bunpack = string.unpack
    -- luacheck: globals string.unpack
    string.unpack = string_unpack
    -- luacheck: globals string.pack
    string.pack = string_pack
end

您声明代码正在运行。问题是什么?不幸的是,不同的命名约定是你不得不接受的。如果您想要可移植性,可以在“需要”之前进行操作系统检查。但是,lua51没有本机的功能来实现这一点。代码只在linux openresty中工作,在windows openresty下不工作,但在windows lua命令行中工作,这就是问题所在