Skip to content

Commit 34cb049

Browse files
committed
Recursive imports
1 parent 7dcdcb0 commit 34cb049

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

Examples/imports.owpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Rule "Debug Import"
44
Actions
5-
debug_msg("Hello!")
5+
debug_func("Hello!")

Examples/lib/child.owpy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#import 'lib2/child2.owpy'
22

3-
%debug_msg(text)
3+
%debug_func(text)
44
Msg(Everyone, text)
5-
6-
nested(Lucio)
5+
nested(Lucio)

Examples/lib/lib2/child2.owpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
%nested(hero_)
2-
Set Hero(hero_)
2+
Set Hero(Event Player, hero_)

OWScript/Transpiler.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,29 @@ def resolve_skips(self):
122122
for skip, jump in zip(skips, skip_to[::-1]):
123123
self.curblock[skip] = self.curblock[skip].format(jump)
124124

125-
def resolve_import(self, node):
125+
def resolve_import(self, node, scope):
126126
# TODO - Resolves imports recursively
127-
children = self.visit(child).children
127+
children = self.visit(node, scope).children
128128
nodes = []
129129
for child in children:
130130
if type(child) == Import:
131-
pass
131+
cur_path = self.path
132+
self.path = os.path.join(os.path.dirname(self.path), os.path.dirname(node.path)) + '\\'
133+
result = self.resolve_import(child, scope)
134+
self.path = cur_path
135+
nodes = result + nodes
132136
else:
133137
nodes.append(child)
134-
return nodes + node.children[1:]
138+
return nodes
135139

136140
def visitScript(self, node, scope):
137141
code = r'rule("Generated by https://github.com/adapap/OWScript") { Event { Ongoing - Global; } Actions { Set Global Variable At Index(A, 0, Round To Integer(Add(Distance Between(Nearest Walkable Position(Vector(-500.000, 0, 0)), Nearest Walkable Position(Vector(500, 0, 0))), Distance Between(Nearest Walkable Position(Vector(0, 0, -500.000)), Nearest Walkable Position(Vector(0, 0, 500)))), Down)); }}' + '\n'
138142
while len(node.children) > 0:
139143
child = node.children[0]
140144
if type(child) == Import:
141-
node.children = self.resolve_import(node)
145+
node.children = self.resolve_import(child, scope) + node.children[1:]
142146
else:
143-
code += self.visit(child)
147+
code += self.visit(child, scope)
144148
node.children = node.children[1:]
145149
return code.rstrip('\n')
146150

0 commit comments

Comments
 (0)