fengari-lua / fengari

🌙 φεγγάρι - The Lua VM written in JS ES6 for Node and the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting fetch response in lua

DoubleShotgun opened this issue · comments

I want to do this:

fetch(url)
.then(response => response.json()).then(json => {
  console.log(json)
})

But in lua.

I tried this:

local promise = window:fetch(url)

promise["then"](promise, function() --[[get response?]] end)

But I have no idea how to get the response.

Just add the argument to the callback function signature.

Like this?
promise["then"](promise, function(response) print(response) end) if so, it is just given me a nil.

Btw the link I'm using does work.

Yes the first argument is this which is null in this context. Add a second one