|
|
If using the local and global, parsing automatic, dictionaries, it's
safe to use local dictionary test inside macros. This capability is
essential to the macro, optional parameter defaulting also new to v3.8.
#macro Foo(P1, optional P2)
#ifndef(local.P2) #local P2 = 0; #end // provide default for P2
...
#end
Otherwise, be very careful as there is at least one bug and also some
complicated behavior - which might or might not be the best thing to
do... Basically, other documented behavior may or may not work!
Details
-------------------------
Recently, I again wondered, how the, new at v3.8 and later, 'global' and
'local' dictionaries of identifiers worked at the very top level. The
#local identifiers are effectively globals when used at the very top of
the scene hierarchy.
Well, in the top file, #local identifiers are added to both the parser's
automatic local and global dictionaries of identifiers. Also true for
all #declare identifiers, declares from the command line, #for loops
iteration variables (treated internally as non-scoped #local(s)) and
such in the top file.
The implication here, if leaning on the local / global dictionaries to
decide things in your scene, is that the conditional test results will
change as you move code about in the hierarchy of files. Some of this we
might expect, while other behavior very likely not.
The bug
----------------------
I went on to do a bunch of test cases on and off over a the past couple
days and that testing turned up relatively basic bug.
If we have three files in A.pov, B.inc, and C.inc where the include
chain is:
A.pov -> B.inc -> C.inc
where we have #local identifiers defined in B.inc, these are not getting
added to the global (or local for that matter) dictionary while reading
/ including C.inc. This a bug.
Those B.inc scoped variables are effectively global for the code in
C.inc. A #declare in C.inc for #local identifier names in B.inc will
update those identifiers in the B.inc scope - ones 'effectively global'
while in C.inc. The #ifdef(), #ifndef() and defined() all return the
appropriate results for the #local identifiers in B.inc. Namely, those
older features see the the #local names in B.inc as defined while in
C.inc. I've attached a failing test case tarball set up with A.pov ->
B.inc -> C.inc.
Aside: I suspect this bug might have gotten passed us due the top level
seeing all the methods of setting up identifiers as creating global ones
(and local). If we imagine the testing was done with something more
like: A.pov -> B.inc alone. Well, things work then because of that
global/local duality in the very top file.
Not sure when I'll get around to looking at the bug. My current leaning
for the global/local duality at the top is everything should be in the
global dictionary and not the local one too, but, I should let that
thought bang around in my head for a while.
Bill P.
Post a reply to this message
Attachments:
Download 'local_global_dictbug.tar.gz' (2 KB)
|
|