I have some libraries that call external optional user functions. The
external functions may be defined in the main code or in another library.
The external function code may include some constants to be accessed (used)
by the main code. To avoid errors when the external functions are not
defined (because their operations are not required by the main code) I
thought to define them in the caller libraries with a dummy code to be
superseded by an external one if any.
My trouble is how and where to reference the libraries. To be more specific:
suppose the library A.scad calls the external function f(). In one scenario,
f() and some constant _TYPE are defined in another user library B.scad. The
main code Main.scad calls some functions of A.scad that will call f from
B.scad. Besides, Main.scad has to access constant _TYPE. How I use/include
those libraries to have the correct references? In what order?
In another scenario, Main.scad don't need any call of A.scad that calls f().
In this case, I would expect that the dummy f() defined in A.scad avoids any
"unknown function" error if B.scad is not used/included.
--
View this message in context: http://forum.openscad.org/Libraries-with-external-calls-tp21093.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Without testing.
Ronaldo wrote
I have some libraries that call external optional user functions. The
external functions may be defined in the main code or in another library.
The external function code may include some constants to be accessed
(used) by the main code. To avoid errors when the external functions are
not defined (because their operations are not required by the main code) I
thought to define them in the caller libraries with a dummy code to be
superseded by an external one if any.
My trouble is how and where to reference the libraries. To be more
specific: suppose the library A.scad calls the external function f(). In
one scenario, f() and some constant _TYPE are defined in another user
library B.scad. The main code Main.scad calls some functions of A.scad
that will call f from B.scad. Besides, Main.scad has to access constant
_TYPE. How I use/include those libraries to have the correct references?
In what order?
Pseudo coding the above
Lib: A { function somef(q) = f()q; someNOTf(r)= rPI; }
Lib: B { function f() = (1); _TYPE=2; } // must NOT use<> to get access to
_TYPE
Main: { somef(_TYPE); }
I would, in Main;
include< B> // f() defined & _TYPE assigned
include< A> // main knows about f(), could also use<> in this case
(but see the wiki ref below)
In another scenario, Main.scad don't need any call of A.scad that calls
f(). In this case, I would expect that the dummy f() defined in A.scad
avoids any "unknown function" error if B.scad is not used/included.
You don't need a dummy f() it is only an error if somef() actually gets
called without f() being defined, if mainV2 only calls someNOTf() & doesn't
need _TYPE, it doesn't need to include< B>. Tho you could if you want _TYPE.
It can get complex, definition v's instantiation, study the example here
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement#Scope_of_variables
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Libraries-with-external-calls-tp21093p21101.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
I don't know why but your example seems not work with use <A.scad> , only
with include <A.scad>
2017-04-06 0:28 GMT-03:00 MichaelAtOz oz.at.michael@gmail.com:
Without testing.
Ronaldo wrote
I have some libraries that call external optional user functions. The
external functions may be defined in the main code or in another library.
The external function code may include some constants to be accessed
(used) by the main code. To avoid errors when the external functions are
not defined (because their operations are not required by the main code)
I
thought to define them in the caller libraries with a dummy code to be
superseded by an external one if any.
My trouble is how and where to reference the libraries. To be more
specific: suppose the library A.scad calls the external function f(). In
one scenario, f() and some constant _TYPE are defined in another user
library B.scad. The main code Main.scad calls some functions of A.scad
that will call f from B.scad. Besides, Main.scad has to access constant
_TYPE. How I use/include those libraries to have the correct references?
In what order?
Pseudo coding the above
Lib: A { function somef(q) = f()q; someNOTf(r)= rPI; }
Lib: B { function f() = (1); _TYPE=2; } // must NOT use<> to get access to
_TYPE
Main: { somef(_TYPE); }
I would, in Main;
include< B> // f() defined & _TYPE assigned
include< A> // main knows about f(), could also use<> in this case
(but see the wiki ref below)
In another scenario, Main.scad don't need any call of A.scad that calls
f(). In this case, I would expect that the dummy f() defined in A.scad
avoids any "unknown function" error if B.scad is not used/included.
You don't need a dummy f() it is only an error if somef() actually gets
called without f() being defined, if mainV2 only calls someNOTf() & doesn't
need _TYPE, it doesn't need to include< B>. Tho you could if you want
_TYPE.
It can get complex, definition v's instantiation, study the example here
<https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/
Include_Statement#Scope_of_variables>
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/
Libraries-with-external-calls-tp21093p21101.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
What error?
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Libraries-with-external-calls-tp21093p21112.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
2017-04-07 2:50 GMT-03:00 MichaelAtOz oz.at.michael@gmail.com:
What error?
Well that's not as I expect.
I think use<> has a dodgy implementation, it defines a scope that is not
visible (apart from functions & modules) to the main program, where its own
variables live. I assumed it would have access to the calling scope, but
obviously not.
What happens if you include<user_file> in lib, as you seem to have tried?
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Libraries-with-external-calls-tp21093p21124.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
2017-04-07 20:48 GMT-03:00 MichaelAtOz oz.at.michael@gmail.com:
Well that's not as I expect.
I think use<> has a dodgy implementation, it defines a scope that is not
visible (apart from functions & modules) to the main program, where its own
variables live. I assumed it would have access to the calling scope, but
obviously not.
What happens if you include<user_file> in lib, as you seem to have tried?
It may work but it is far from fair: it is not reasonable the user need to
change a library file nor to define something he/she doesn't really need.
In the ideal situation the main code would register his/her function
calling a lib function. But we don't have (yet, I hope) first class
functions in OpenSCAD. I am trying a work around.
Another awkward situation I found: if I redefine the function my_function()
in the higher scope of the user code, it overrides the definition in the
user_file.scad but if it is redefined inside a module it will not override
it. Damn it!