我想在存储的内部使用luarocks模块 luajit pllua使用。
例如
luarocks install lua-requests
示例功能
CREATE FUNCTION request_test (list text[])
RETURNS text[] AS $$
-- set_paths.lua
local version = _VERSION:match("%d+%.%d+")
package.path = './?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;' .. package.path
package.cpath = './?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;' ..package.cpath
--requests = require('requests')
local requests = require('/usr/local/share/lua/5.1/requests.lua')
list[7] = 'check'
return list
$$ LANGUAGE pllua;
使用。
select request_test(ARRAY['q','w','e']);
执行结果。
ERROR: [string "request_test"]:7: attempt to call global 'require' (a nil value)
CONTEXT:
stack traceback(trusted):
[string "request_test"]:7: in function <[string "request_test"]:1>
********** Error **********
ERROR: [string "request_test"]:7: attempt to call global 'require' (a nil value)
SQL state: 38000
Context:
stack traceback(trusted):
[string "request_test"]:7: in function <[string "request_test"]:1>
pathcheck
CREATE FUNCTION require_test ()
RETURNS text[] AS $$
local list = {}
list[1] = _VERSION:match("%d+%.%d+")
list[2] = package.path
list[3] = package.cpath
list[4] = 'test'
return list
$$ LANGUAGE pllua;
结果
select require_test()
5.1,./?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua,./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so,test
全球'需要'(零值)?
我如何需要luarocks模块?