public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>(); try { string key = Guid.NewGuid().ToString(); string value = Guid.NewGuid().ToString(); lua.CreateTable(); lua.PushString(value); lua.SetField(-2, key); lua.PushNil(); lua.Next(-2); string received_key = lua.GetString(-2); string received_value = lua.GetString(-1); lua.Pop(3); if (received_key != key || received_value != value) { throw new NextTestException("Received key value pair is invalid"); } taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }
void SetPlayerList(ILua lua) { if (!getPlayersTasks.IsEmpty) { List <string> players = new List <string>(); Exception executionException = null; try { lua.PushGlobalTable(); lua.GetField(-1, "player"); lua.GetField(-1, "GetAll"); lua.MCall(0, 1); lua.PushNil(); while (lua.Next(-2) != 0) { lua.GetField(-1, "Nick"); lua.Push(-2); lua.MCall(1, 1); players.Add(lua.GetString(-1)); lua.Pop(2); } lua.Pop(lua.Top()); } catch (Exception e) { executionException = e; } TaskCompletionSource <List <string> > task; while (getPlayersTasks.TryDequeue(out task)) { if (executionException == null) { task.SetResult(players); } else { task.SetException(executionException); } } } }