Skip to content

Commit

Permalink
Remove generalized iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketasaja committed Oct 7, 2024
1 parent 7f73afc commit 54af54e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 72 deletions.
2 changes: 1 addition & 1 deletion docs/config/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const example = `event MyEvent = {
}`

const pollingExample = `-- Example of using a Zap polling event on the server.
for player, payload in zap.my_event do
for player, payload in zap.my_event.iter() do
print(player, payload)
end`
</script>
Expand Down
39 changes: 3 additions & 36 deletions zap/src/output/luau/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ impl<'src> ClientOutput<'src> {
self.push_line(&format!("{send_events} = noop,"));

for ev in self.config.evdecls.iter() {
if ev.call == EvCall::Polling && ev.from == EvSource::Server {
self.push_line(&format!("{name} = table.freeze(setmetatable({{", name = ev.name));
} else {
self.push_line(&format!("{name} = table.freeze({{", name = ev.name));
}
self.push_line(&format!("{name} = table.freeze({{", name = ev.name));
self.indent();

if ev.from == EvSource::Client {
Expand All @@ -78,12 +74,6 @@ impl<'src> ClientOutput<'src> {
}

self.dedent();
if ev.call == EvCall::Polling && ev.from == EvSource::Server {
self.push_line("}), {");
self.indent();
self.push_line("__iter = noop,");
self.dedent();
}
self.push_line("}),");
}

Expand Down Expand Up @@ -737,11 +727,7 @@ impl<'src> ClientOutput<'src> {
.iter()
.filter(|ev_decl| ev_decl.from == EvSource::Server)
{
if let EvCall::Polling = ev.call {
self.push_line(&format!("{name} = setmetatable({{", name = ev.name));
} else {
self.push_line(&format!("{name} = {{", name = ev.name));
}
self.push_line(&format!("{name} = {{", name = ev.name));
self.indent();

if let EvCall::Polling = ev.call {
Expand All @@ -755,26 +741,7 @@ impl<'src> ClientOutput<'src> {
}

self.dedent();
match ev.call {
EvCall::Polling => {
self.push_indent();
self.push("}, {\n");
self.indent();
let id = ev.id;
self.push_indent();
self.push(&format!("__iter = polling_iterators[{id}] :: () -> "));
if let Some(data) = &ev.data {
self.push("(() -> ");
self.push_ty(&data);
self.push("),\n");
} else {
self.push("(() -> true),\n")
}
self.dedent();
self.push_line("}),");
}
_ => self.push_line("},"),
}
self.push_line("},");
}
}

Expand Down
38 changes: 3 additions & 35 deletions zap/src/output/luau/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ impl<'a> ServerOutput<'a> {
self.push_line(&format!("{send_events} = noop,"));

for ev in self.config.evdecls.iter() {
if ev.call == EvCall::Polling && ev.from == EvSource::Client {
self.push_line(&format!("{name} = table.freeze(setmetatable({{", name = ev.name));
} else {
self.push_line(&format!("{name} = table.freeze({{", name = ev.name));
}
self.push_line(&format!("{name} = table.freeze({{", name = ev.name));
self.indent();

if ev.from == EvSource::Client {
Expand All @@ -90,12 +86,6 @@ impl<'a> ServerOutput<'a> {
}

self.dedent();
if ev.call == EvCall::Polling && ev.from == EvSource::Client {
self.push_line("}), {");
self.indent();
self.push_line("__iter = noop,");
self.dedent();
}
self.push_line("}),");
}

Expand Down Expand Up @@ -882,10 +872,7 @@ impl<'a> ServerOutput<'a> {
.iter()
.filter(|ev_decl| ev_decl.from == EvSource::Client)
{
match ev.call {
EvCall::Polling => self.push_line(&format!("{name} = setmetatable({{", name = ev.name)),
_ => self.push_line(&format!("{name} = {{", name = ev.name)),
}
self.push_line(&format!("{name} = {{", name = ev.name));
self.indent();

if let EvCall::Polling = ev.call {
Expand All @@ -899,26 +886,7 @@ impl<'a> ServerOutput<'a> {
}

self.dedent();
match ev.call {
EvCall::Polling => {
self.push_indent();
self.push("}, {\n");
self.indent();
let id = ev.id;
self.push_indent();
self.push(&format!("__iter = polling_iterators[{id}] :: () -> "));
if let Some(data) = &ev.data {
self.push("(() -> (Player, ");
self.push_ty(&data);
self.push(")),\n");
} else {
self.push("(() -> (Player, true)),\n")
}
self.dedent();
self.push_line("}),");
}
_ => self.push_line("},"),
}
self.push_line("},");
}

for fndecl in self.config.fndecls.iter() {
Expand Down

0 comments on commit 54af54e

Please sign in to comment.