Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua http.request return attempt to index global 'http' (a nil value)

Tags:

sockets

lua

I just try simple lua code:

local http = require("socket.http")
local  b, c, h = http.request("http://www.example.com/")

But I get this error:

stdin:1: attempt to index global 'http' (a nil value)
stack traceback:
        stdin:1: in main chunk
        [C]: ?

luasocket is installed and lua find it, anyone can help?

like image 684
Arash Avatar asked Oct 22 '25 06:10

Arash


1 Answers

The lua repl runs each line in its own context. Local variables don't stick around from line to line. Drop the local on the first line and http will be available in the second line in the repl.

If b, c and h are nil that sounds like the call failed for some reason.

like image 51
Etan Reisner Avatar answered Oct 25 '25 21:10

Etan Reisner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!