Skip to content

Commit

Permalink
On returns disconnect function (#62)
Browse files Browse the repository at this point in the history
* On returns disconnect function

Zap.Event.On() returns a function to disconnect the listener

* Corrected issues

* Added functionality for client

* Format server

* Format server and client
  • Loading branch information
xSwezan authored Jan 14, 2024
1 parent 0dde32a commit 4ddd5e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions zap/src/output/luau/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ impl<'src> ClientOutput<'src> {
self.push_line(&format!("event_queue[{id}] = 0"));
}

self.push_line("return function()");
self.indent();

self.push_line(&format!(
"table.remove(events[{id}], table.find(events[{id}], {callback}))"
));

self.dedent();
self.push_line("end");

self.dedent();
self.push_line("end,");
}
Expand Down
12 changes: 11 additions & 1 deletion zap/src/output/luau/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,21 @@ impl<'a> ServerOutput<'a> {
self.push_ty(ty);
}

self.push(") -> ())\n");
self.push(") -> ()): () -> ()\n");
self.indent();

self.push_line(&format!("table.insert(events[{id}], {callback})"));

self.push_line("return function()");
self.indent();

self.push_line(&format!(
"table.remove(events[{id}], table.find(events[{id}], {callback}))"
));

self.dedent();
self.push_line("end");

self.dedent();
self.push_line("end,");
}
Expand Down

0 comments on commit 4ddd5e3

Please sign in to comment.