List Info

Thread: Can I use other rules and variables that they are in different scope?




Can I use other rules and variables that they are in different scope?
user name
2007-10-16 20:01:53
Hello.
 
Please, look at that code below.
 
# Jamroot
 
import xxx ;
 
# in xxx.jam file
 
SOME_DIR_PATH1 = /home/user/test ;
 
rule path-constants ( name )
{
    SOME_DIR_PATH2 = /home/user/test ;
 
    return $($(name)) ;
}
 
class Test
{
   rule __init__ ( )
   {
      echo "[" $(SOME_DIR_PATH1) "]" ;
      echo "[" [ path-constants SOME_DIR_PATH2 ] "]" ;
   }
}
 
import "class" : new ;
 
t = [ new Test ] ;
 
 
# outputs
$> bjam
[ ] "echo $(SOME_DIR_PATH1) - value is empty";
/home/user/test/test.jam:16: in object(Test)15.__init__
rule path-constants unknown in module object(Test)15.
...
...
 
 
I can't access variables and rules that are in different scope, I mean not in class scope. why?
Are there any rule or something ? How can I solve this? Are there any solution?
 
Thanks in advance.
Re: Can I use other rules and variables that they are in different scope?
country flaguser name
Russian Federation
2007-10-17 02:14:33
On Wednesday 17 October 2007 05:01:53 김영현 wrote:
> Hello.
> 
> Please, look at that code below.
> 
> # Jamroot
> 
> import xxx ;
> 
> # in xxx.jam file
> 
> SOME_DIR_PATH1 = /home/user/test ;
> 
> rule path-constants ( name )
> {
>     SOME_DIR_PATH2 = /home/user/test ;
> 
>     return $($(name)) ;
> }
> 
> class Test
> {

You need

	import xxx ;

here.

>    rule __init__ ( )
>    {
>       echo "[" $(SOME_DIR_PATH1)
"]" ;

I don't think you can get at variable line this. [
modules.peek xxx : SOME_DIR_PATH1 ]
might work.

>       echo "[" [ path-constants
SOME_DIR_PATH2 ] "]" ;

and here, with import in place, xxx.path-constants should
work.

> import "class" : new ;
> 
> t = [ new Test ] ;
> 
> 
> # outputs
> $> bjam
> [ ] *"echo $(SOME_DIR_PATH1) - value is
empty"
> */home/user/test/test.jam:16: in object(Test)15.__init__
> rule *path-constants unknown* in module
object(Test)15.
> ...
> ...
> 
> 
> I can't access variables and rules that are in
different scope, I mean not
> in class scope. why?

Because there's no scoping in jam. There are modules, and
each module has
its own namespace. class, actually, is a module in disguise.
Inside
module, you can access variables of that module, only. The
fact that
class is defined inside some other module does not help.

- Volodya
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )