有一个名为lua-pack.c的c代码,提供了here,它是进程十六进制字符串的lua扩展,我需要在openresty中使用它来处理一些网络流。
我将其安装在带有lua5.1和luarocks的Windows中
我成功获取了lua-pack.dll。像这样在命令行模式下所有测试都成功运行了
lua C:\ projects \ lua-pack \ lua-pack \ test.lua
但是一旦我把这个lua-pack.dll放在openresty的目录中并使用它,就会抛出一些异常
worker process 24892 exited with code C0000005
我可以在ubuntu中成功编译lua-pack.so(通过makefile编译),并且它可以在Linux的openresty中正常运行。我试图将这个lua-pack.so复制到Windows,并且抛出异常,提示这不是Windows的用途。
但是,我注意到在test.lua由作者提供的here中,它是require(pack)而不是require(lua_pack)
所以我将lua-pack.dll重命名为pack.dll,然后又遇到另一个异常
lua entry thread aborted: runtime error: error loading module 'pack' from file '.\pack.dll':
我确实注意到这是lua-rocks窗口中的pack.lua,我不知道这是否重要。
作者提供的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