Pocket Plane Group
Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: Galactygon on April 11, 2017, 03:20:09 AM
-
How exactly are arrays remembered when generated within a function?
I have an example of:
DEFINE_ACTION_FUNCTION "PRINT_TEST"
STR_VAR print_list = ""
done_deal = "DEFAULT"
RET done_deal
BEGIN
PRINT "%print_list%"
ACTION_PHP_EACH "%print_list%" AS one => two BEGIN
PRINT "%one% => %two%"
END
ACTION_DEFINE_ASSOCIATIVE_ARRAY "%done_deal%" BEGIN
U => V
W => X
Y => Z
END
END
ACTION_DEFINE_ASSOCIATIVE_ARRAY "TEST" BEGIN
A => B
C => D
E => F
END
LAF "PRINT_TEST" STR_VAR print_list = "TEST" RET done_deal END
PRINT "%done_deal%"
ACTION_PHP_EACH "%done_deal%" AS three => four BEGIN
PRINT "%three% => %four%"
END
This will print the contents of array "TEST" (i.e. "TEST" %WNL% A => B %WNL% C => D %WNL% E => F) but the array "DEFAULT" (U => V, W => X, Y => Z) will not be printed, only the letters "DEFAULT".
Is there a way to return arrays generated within a function like any other variable?
-
Arrays go out of scope with the function, just like variables (arrays are implemented as variables). You cannot return arrays. You could would not work, regardless, however, as you are defining an array rooted in "DEFAULT", but are returning the value of the variable called "done_deal" (and the value is "DEFAULT" because the function never assigns to "done_deal" so the default value is retained).
-
Thanks for the reply. I guess I could try inlining and reincluding stuff if I get desperate. I have settled with macros for now which work for the stuff I want to do.