Skip to content

Commit

Permalink
docs: adjust role explanation for NextRelation (#757)
Browse files Browse the repository at this point in the history
The current docs describe a single return value that is an array of size 2,
but the `NextRelation()` function actually has two return values.

See https://www.lua.org/pil/5.1.html for more.

Hat tip to @BenOnTrack, who noticed it in #749
  • Loading branch information
cldellow authored Sep 20, 2024
1 parent 6509f0c commit 28d7e99
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/RELATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ Examine the tags using `Find(key)` as normal. (You can also use `Holds(key)` and

### Stage 2: accessing relations from ways and nodes

Now that you've accepted the relations, they will be available from `way_function` or `node_function`. They are accessed using an iterator (`NextRelation()`) which reads each relation for that way in turn, returning nil when there are no more relations available. Once you have accessed a relation with the iterator, you can read its tags with `FindInRelation(key)`. For example:
Now that you've accepted the relations, they will be available from `way_function` or `node_function`. They are accessed using an iterator (`NextRelation()`) which reads each relation ID for that way in turn, returning nil when there are no more relations available. Once you have accessed a relation with the iterator, you can read its tags with `FindInRelation(key)`. For example:

```lua
while true do
local rel = NextRelation()
if not rel then break end
local relation_id = NextRelation()
if not relation_id then break end
print ("Part of route "..FindInRelation("ref"))
end
```

You can obtain the relation ID and role from `rel`, which is a list (a two-element Lua table). The first element (`rel[1]`) is the id, the second (`rel[2]`) the role. Remember Lua tables are 1-indexed!
You can also obtain the relation role by accessing the second return value of `NextRelation()`:

```lua
local relation_id, role = NextRelation()
```

Should you need to re-read the relations, you can reset the iterator with `RestartRelations()`.

Expand Down

0 comments on commit 28d7e99

Please sign in to comment.