pkulchenko / ZeroBranePackage

Packages for ZeroBrane Studio (https://studio.zerobrane.com)
MIT License
246 stars 148 forks source link

[Debug Redis] redis.lua:1831: attempt to index global 'socket' (a nil value) #99

Closed xrayw closed 10 months ago

xrayw commented 10 months ago

Hello, I use this useful lua ide to debug redis lua. I meet this error in debug mode.

Program starting as '"/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/bin/lua.app/Contents/MacOS/lua" "/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/packages/redis.lua" --instance redis://localhost:6379 --controller localhost:8172 --debug yes "/Users/user/Desktop/2.lua" txt , 1 2'.
Program 'lua' started in '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/myprograms' (pid: 13869).
/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/bin/lua.app/Contents/MacOS/lua: ...neStudio.app/Contents/ZeroBraneStudio/packages/redis.lua:1831: attempt to index global 'socket' (a nil value)
stack traceback:
    ...neStudio.app/Contents/ZeroBraneStudio/packages/redis.lua:1831: in main chunk
    [C]: at 0x010091edc0
Program completed in 0.13 seconds (pid: 13869).

but if i execute it directly(not in debug mode), no error report

lua version: 5.4 redis-lua: 2.0.4

pkulchenko commented 10 months ago

@xrayw, it looks like socket is expected to be a global variable, but the newer version of luasocket may not provide that. Can you try replacing socket in socket.tcp with require("socket"), so the line 1831 looks like this:

local server, err = require("socket").tcp()
xrayw commented 10 months ago

@pkulchenko Hi, boss, require("socket").tcp() works for me. thank you very much.

my luasocket version: 3.1.0-1

i think we can check if the global socket is nil. we use require("socket").tcp()

pkulchenko commented 10 months ago

I pushed a fix for it, but it can probably be updated to use (require"socket" or socket).tcp() to also work with some older "luasocket" versions. Does that still work for you?

xrayw commented 10 months ago

@pkulchenko (require"socket" or socket).tcp() also works for me.