2

I have an issue with attempting to utilize ngx on any of the lua coding in ZeroBrane Studio, including resty.cookie. Am I doing something wrong? (This is in Windows)

I have OpenResty downloaded, but I have no idea how to compile the ngx inside despite looking at multiple instructions on how to do so, as all of the attempt made on debugging always results in "attempt to index global 'ngx' (a nil value)".

EDIT: To rephrase, I am using ZeroBrane Studios, OpenResty and StrawberryPerl. I am trying to utilize resty.cookie that I had downloaded via LuaRocks to pull a cookie from a certain site (httpbin.org). However, I noticed that whenever I run the debugger, it ends up with "attempt to index global 'ngx' (a nil value)" at the "require resty.cookie" line. I decided to look at the guide that was shown in the website. It showed the same thing, so I have no idea how to fix this issue.

Vac
  • 33
  • 1
  • 4
  • Can you elaborate more on what you're doing? – 0xInfection Jan 23 '19 at 06:40
  • I am trying to get the cookie from a specific site using "Zerobrane Studio". However, every time I tried to use "ngx" (For example, "local cookie_value = ngx.var.cookie_2"), it automatically resulted in the specified error. – Vac Jan 23 '19 at 06:52
  • Do you follow these [instructions](http://notebook.kulchenko.com/zerobrane/debugging-openresty-nginx-lua-scripts-with-zerobrane-studio) ? – Egor Skriptunoff Jan 23 '19 at 07:49
  • Yes I did. However, at the point where I was supposed to create content.lua, the error appeared with "attempt to index global 'ngx' (a nil value)" at second line whenever I execute the debug. – Vac Jan 23 '19 at 07:50
  • Updated the main question to be more precise. – Vac Jan 24 '19 at 10:57
  • Just a theory... Are you, by any chance, executing standalone Lua and expecting it to know about OpenResty? `nginx` is only available within Openresty. – DarkWiiPlayer Jan 25 '19 at 13:06

1 Answers1

1

I think you mistakenly believe that openresty is some sort of Lua library that lets you do HTTP stuff. It's not. Nginx is a web server and OpenResty is just a modified version of it that lets you generate your websites dynamically using Lua.

If you want to communicate over HTTP from within plain Lua, you need something different (like Luasocket or LuaHTTP).

DarkWiiPlayer
  • 6,871
  • 3
  • 23
  • 38