Skip to content

Commit

Permalink
Add support for getting links by index (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartycope authored Aug 18, 2024
1 parent cf3095c commit 3119427
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyndustri.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ from typing import Iterator, Optional, Union
class Link:
"""Represents a link."""

def __getitem__(self, n) -> Building | None:
"""Gets the nth link"""

class Env:
"""
Access to special environmental variables.
Expand Down
5 changes: 5 additions & 0 deletions pyndustric/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,11 @@ def as_value(self, node, output: str = None):
self.ins_append(f"read {output} {cell} {val}")
return output

if isinstance(node.value, ast.Name) and node.value.id == "Link":
val = self.as_value(node.slice)
self.ins_append(f"getlink {output} {val}")
return output

# container1[dynamic_res]
# 'some_object'['some_resource']
obj = self.as_value(node.value).strip('"')
Expand Down
8 changes: 8 additions & 0 deletions test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,11 @@ def test_None():
set foo @null
"""
foo = None


@masm_test
def test_Link():
"""
getlink l 2
"""
l = Link[2]

0 comments on commit 3119427

Please sign in to comment.