I could have sworn I had this figured out but it seems I do not. I’m trying to create a function that handles http.requests. You pass a url such as img = getFile(“url here”). However the http.request() moves on before the success callback function thus img will be = to nil. Is there any way to pass a reference to a funcion so the function could edit the reference? such as:
local img = nil
img = hlib.getFile("url here",img)
--img stays nill do to the function finishing before the callback
hlib.getFile = function(file,ret)
function didGetData(data,status,head)
print(status)
--any way to use ret as a pointer to img so I can set img here?
ret = data
print("File Request Sucess!")
end
http.request(file,didGetData)
return ret
end
I hope I’m being clear enough. Basically hlib.getFile is being imported into projects. I use it to get multiple http requests so i cant have a set variable to hold the returned data. if http.request would wait for the callback to finish it would be easy to just use return.