Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load the cjson module into luajit CLI #239

Open
ADUDevEx opened this issue Oct 12, 2023 · 1 comment
Open

Can't load the cjson module into luajit CLI #239

ADUDevEx opened this issue Oct 12, 2023 · 1 comment

Comments

@ADUDevEx
Copy link

ADUDevEx commented Oct 12, 2023

Environment

Computer : Mac Book M2
Docker : 24.0.6, build ed223bc820
Docker image : openresty/openresty:1.21.4.1-8-alpine-fat

Issue

CJSON is supposed to be available on the Docker image

Demo

~ $ docker run -ti openresty/openresty:1.21.4.1-8-alpine-fat sh
/ # env
HOSTNAME=6a0edb9ed3dc
LUA_PATH=/usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
LUA_CPATH=/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so
PWD=/
/ # find / -name "*cjson*"
/usr/local/openresty/lualib/cjson.so
/usr/local/openresty/pod/lua-cjson-2.1.0.10
/usr/local/openresty/pod/lua-cjson-2.1.0.10/lua-cjson-2.1.0.10.pod
/ # luajit
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/
JIT: ON fold cse dce fwd dse narrow loop abc sink fuse
> local cjson = require("cjson")
> if not cjson then
>> print("no")
>> end
no

/ # luarocks install lua-cjson
Installing https://luarocks.org/lua-cjson-2.1.0.10-1.src.rock
lua-cjson 2.1.0.10-1 depends on lua >= 5.1 (5.1-1 provided by VM)
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c lua_cjson.c -o lua_cjson.o
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c strbuf.c -o strbuf.o
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c fpconv.c -o fpconv.o
gcc  -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o
No existing manifest. Attempting to rebuild...
lua-cjson 2.1.0.10-1 is now installed in /usr/local/openresty/luajit (license: MIT)

/ # find / -name "*cjson*"
/usr/local/openresty/luajit/share/lua/5.1/cjson
/usr/local/openresty/luajit/lib/lua/5.1/cjson.so
/usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-cjson
/usr/local/openresty/luajit/lib/luarocks/rocks-5.1/lua-cjson/2.1.0.10-1/lua-cjson-2.1.0.10-1.rockspec
/usr/local/openresty/lualib/cjson.so
/usr/local/openresty/pod/lua-cjson-2.1.0.10
/usr/local/openresty/pod/lua-cjson-2.1.0.10/lua-cjson-2.1.0.10.pod
/var/cache/luarocks/https___luarocks.org/lua-cjson-2.1.0.10-1.src.rock

/ # luajit
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/
JIT: ON fold cse dce fwd dse narrow loop abc sink fuse
> local cjson = require("cjson")
> if not cjson then
>> print("no")
>> end
no

I hope I'm not just overlooking a step to load it.
Let me know if you need more information and thanks in advance for your help.

@neomantra
Copy link
Member

The LuaRocks CJSON won't work without pat adjustment, but CJSON should be built-in.

Try these commands to verify:

> docker run -ti --rm openresty/openresty:1.21.4.1-8-alpine-fat sh -c "luajit -e \"print(require('cjson'))\""
table: 0x581979746f08

> docker run -ti --rm openresty/openresty:1.21.4.1-8-alpine-fat sh -c "luajit -e \"for k, v in pairs(require('cjson')) do print(k,v) end\""
new	function: 0x23f05180eef0
null	userdata: NULL
empty_array_mt	table: 0x23f05180e0a8
array_mt	table: 0x23f05180e0f0
empty_array	userdata: 0x7fffb48bd988
_NAME	cjson
_VERSION	2.1.0.10
encode	function: 0x23f05180e7c0
decode	function: 0x23f05180e838
encode_empty_table_as_object	function: 0x23f05180e8a0
decode_array_with_array_mt	function: 0x23f05180e988
encode_sparse_array	function: 0x23f05180ea08
encode_max_depth	function: 0x23f05180e920
decode_max_depth	function: 0x23f05180eb48
encode_number_precision	function: 0x23f05180ebc0
encode_keep_buffer	function: 0x23f05180ec38
encode_invalid_numbers	function: 0x23f05180ea48
decode_invalid_numbers	function: 0x23f05180eac0
encode_escape_forward_slash	function: 0x23f05180ee70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants