Closed szymski closed 10 years ago
httpRequest("http://webpage.com", function(string Body){ string dupa = Body }, function(){})
Not possiblet because there is a delay when you try get data from other server and you must have callback function. Same principle in lua http://wiki.garrysmod.com/page/http/Fetch.
just freeze lemon until it'll have response
In going to be the first one to say ABSOLUTELY NOT. (That way nobody else has to)
You can't "just freeze lemongate" as it runs on pure gmod lua(which is not freezable). Although you can achieve it using lua coroutines but it would ruin performence as you would have to rewrite whole lemongate compiler and write multiple hacks to achieve it, at the end you will have lemongate that does freeze on httpRequest but run lemongate itself 100 times slower, just because you want httpRequest to wait for response rather using callbacks.
Also some people(including me) don't want the lemongate to freeze as we could execute other stuff while the gate is waiting for http response, such as initialize EGP.
There, if you really want httpRequest to wait, use/edit following code
function httpRequestC(coroutine CR,string S){ // Only works if called inside coroutine
string Return = ""
httpRequest(S,function(string Body){
Return = Body
CR:resume()
},function(){
Return = ""
CR:resume()
})
yield()
return Return
}
@return: httpRequestC string
coroutine C = coroutine(function(){})
C = coroutine(function(){
// Your code here <<<<===================
print(httpRequestC(C,"http://example.com"))
// And here
sleep(2)
print("hello world")
})
C:resume()
This is not going to happen. Closed.
Can you make a function like httpRequest, but which returns http response as string?
Like: string dupa = httpRequest("http://webpage.com")