local module = {}; module.xxx = xxx; functionn module.xxx () -- todo end return module; Lua 模块被 require 之后, 只会运行一次并进行缓存
安装 LuaRocks, 参考openresty 官方 wget http://luarocks.org/releases/luarocks-2.0.13.tar.gz tar -xzvf luarocks-2.0.13.tar.gz cd luarocks-2.0.13/ ./configure --prefix=/usr/local/openresty/luajit \ --with-lua=/usr/local/openresty/luajit/ \ --lua-suffix=jit \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 make sudo make install 安装 lua2go sudo /usr/local/openresty/luajit/luarocks install --server=https://luarocks.org/dev lua2go 通过 lua2go 调用 golang dll local lua2go = require('lua2go') local xxx = lua2go.Load('./xxx.so') lua2go.Externs([ extern char* captcha(xxx) ]) 试用这个ffi 模块,可能多次调用 lua2go.Externs 函数,导致内存泄漏;最好包装成lua module
安装 LuaRocks, 参考openresty 官方 wget http://luarocks.org/releases/luarocks-2.0.13.tar.gz tar -xzvf luarocks-2.0.13.tar.gz cd luarocks-2.0.13/ ./configure --prefix=/usr/local/openresty/luajit \ --with-lua=/usr/local/openresty/luajit/ \ --lua-suffix=jit \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.
