Open Yogpod opened 7 months ago
Thanks for the contribution! FiveM & this proposed addition are going to need a way to sychronize this with script execution, since the HTTP request handlers run asynchronously.
@Yogpod if you are able to adapt your code to synchronize properly, that would be appreciated. Although, for both FiveM & Garry's Mod, PRs are welcome to fix this behavior.
There is no way to run HTTP synchronously, so you'd have to shove the script as a function into the success/failed callback and that may mess with something/not be possible at all.
There is no way to run HTTP synchronously, so you'd have to shove the script as a function into the success/failed callback and that may mess with something/not be possible at all.
It could be possible with coroutines
Something like Something like
coroutine.wrap(function()
local co = coroutine.running()
local code = ""
timer.Simple(0, function()
HTTP({
success = function(c, body, headers)
code = c
coroutine.resume(co)
end,
failure = function()
error("failed")
end,
method = "GET",
url = "https://raw.githubusercontent.com/Luraph/macrosdk/main/luraphsdk.lua"
})
end)
coroutine.yield()
if code then
RunString(code)
end
end)()
Github is messing with my code block for some reason
@Yogpod You have to put the start and ending code block characters on their own line. Does that code work for you?
It appears to work yes
No it does not work nevermind it was piggybacking off my previous execution
@Yogpod remove the coroutine.wrap and move the code inside the function passed as an argument to coroutine.wrap into the top-level. Please let me know if it works or provide me any error messages you receive.
timer is because http library isn't always ready https://wiki.facepunch.com/gmod/Global.HTTP
Could also use CompileString instead of RunString but the source didn't seem to matter to you for the other examples.