Skip to content

Commit

Permalink
Fix compilation in older versions of D
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiascode committed Aug 12, 2024
1 parent 280f1c3 commit 2339eea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/messages.d
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,10 @@ class SRoomList : Message
super(RoomList);

writei(rooms.length); // number of room names we will send
foreach (room ; rooms.keys) writes(room);
foreach (room, users ; rooms) writes(room);

writei(rooms.length); // number of user counts
foreach (users ; rooms.values) writei(users);
foreach (room, users ; rooms) writei(users);

writei(0); // number of owned private rooms(unimplemented)
writei(0); // number of owned private rooms(unimplemented)
Expand Down
4 changes: 4 additions & 0 deletions src/room.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Room
return room_list[roomname];
}

@trusted // .values doesn't work with @safe in old D versions
static Room[] rooms()
{
return room_list.values;
Expand All @@ -72,6 +73,7 @@ class Room
global_room_user_list.remove(username);
}

@trusted // .keys doesn't work with @safe in old D versions
static string[] global_room_users()
{
return global_room_user_list.keys;
Expand Down Expand Up @@ -144,11 +146,13 @@ class Room
return user_list.length;
}

@trusted // .values doesn't work with @safe in old D versions
User[] users()
{
return user_list.values;
}

@trusted // .keys doesn't work with @safe in old D versions
private string[] user_names()
{
return user_list.keys;
Expand Down
3 changes: 2 additions & 1 deletion src/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class Server
return null;
}

@trusted // .keys doesn't work with @safe in old D versions
User[] users()
{
return user_list.values;
Expand Down Expand Up @@ -508,7 +509,7 @@ class Server
private string show_users()
{
string s;
foreach (username ; user_list.keys) s ~= show_user(username) ~ "\n";
foreach (username, user ; user_list) s ~= show_user(username) ~ "\n";
return s;
}

Expand Down
12 changes: 10 additions & 2 deletions src/soulsetup.d
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,21 @@ class Menu
entries[index] = entry;
actions[index] = action;
}


@trusted // .keys doesn't work with @safe in old D versions
string[] sorted_entry_indexes()
{
auto indexes = entries.keys;
sort(indexes);
return indexes;
}

void show()
{
writeln(format( "\n%s\n", title));
if (info.length > 0) writeln(format("%s\n", info));

foreach (index ; sort(entries.keys))
foreach (index ; sorted_entry_indexes)
writeln(format("%s. %s", index, entries[index]));

write("\nYour choice : ");
Expand Down

0 comments on commit 2339eea

Please sign in to comment.