I don’t really know if this is possible, but I’m trying to invoke a lua export that involves a callback by passing an Action
object.
Here is the code:
C#:
void Callback(object x)
{
var info = (object[]) x;
Debug.WriteLine("Callback invoked!");
}
Exports[API.GetCurrentResourceName()].httpRequest("https://google.com/",
"GET", null, null, new Action<object>(Callback));
lua:
function httpRequest(url, method, info, headers, callback)
Citizen.Trace('request received...\n')
info = info or {}
headers = headers or {}
if not callback then
Citizen.Trace('"callback" is nil\n')
return
end
Citizen.Trace('sending out request\n')
PerformHttpRequest(url, function(code, content, headers)
Citizen.Trace('got callback, invoking action')
local res = {code, content, headers}
callback(res)
end, method, json.encode(info, headers))
end
It just keeps tracing ““callback” is nil” so I guess i’m doing something wrong here, or that it is not possible at all. If it’s not possible, is there a workaround?