1

There is a pretty similar question asked here: How to call & await async C# method from Lua / MoonSharp script?

But this doesn't account for arguments. I want this for example to run:

private async Task<string> GetNicknameAsync(ulong id)
{
    return await GetNicknameCodeAsync(id);
}

And then be able to do something like this in lua:

print(getNickname(372983297329234))
Berry
  • 23
  • 7
  • You just need to add the args to the answer in the other question. you would do `function(result) print(result) end` for the lua `callback`. then you just put the result in the `callback.Function.Call(nickName);` – Nifim Aug 14 '20 at 13:44
  • Yeah that much I understood, but is there no way to make it prettier? As in just having to do `print(getNickname(id))`? – Berry Aug 14 '20 at 14:25
  • with no additional lua code? if additional lua code is fine then you define a function that wraps your async function and does all the `callback`, then you have that function accept the `id` pass it to the async and return the result to your print – Nifim Aug 14 '20 at 14:33
  • Hmm, I'll try, thanks. – Berry Aug 14 '20 at 15:03
  • Did you find a resolution for this? I am looking for something similar. – Erik Aug 26 '21 at 13:41

0 Answers0