Skip to content

Commit 41b0458

Browse files
can used functions defined in global vars (normal way)
1 parent 4d7296d commit 41b0458

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/pathsim_utils.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,23 @@ def get_parameters_for_event_class(
275275
if k in ["func_evt", "func_act"]:
276276
# Execute func code if provided
277277
func_code = event_data[k]
278-
if func_code:
279-
try:
280-
exec(func_code, event_namespace)
281-
if k not in event_namespace:
282-
raise ValueError(f"{k} function not found after execution")
283-
except Exception as e:
284-
raise ValueError(f"Error executing {k} code: {str(e)}")
285-
else:
278+
if not func_code:
286279
raise ValueError(f"{k} code is required but not provided")
280+
281+
if func_code in event_namespace:
282+
parameters[k] = event_namespace[func_code]
283+
# parameters[f"{k}_identifier"] = func_code
284+
continue
285+
286+
try:
287+
exec(func_code, event_namespace)
288+
if k not in event_namespace:
289+
raise ValueError(f"{k} function not found after execution")
290+
except Exception as e:
291+
raise ValueError(f"Error executing {k} code: {str(e)}")
292+
287293
parameters[k] = event_namespace[k]
294+
# parameters[f"{k}_identifier"] = k
288295
else:
289296
parameters[k] = eval(user_input, event_namespace)
290297
return parameters

0 commit comments

Comments
 (0)