Forum OpenACS Development: Re: uplevel with passed variables

Collapse
Posted by Samer Abukhait on
I came out to the following solution:

ad_proc -public myProc {Var} {} {
        upvar X_var vv_var
        set vv_var $Var
        uplevel {
          Some Code Using X_var
        }
}
I don’t know if this is the ‘most’ right solution.

Collapse
Posted by Tom Jackson on

If you run:


myProc "var"

#The result will be the same as executing:

Some Code using X_var

You can try to pass things into the uplevel, but it will never work. Your proc would have the same effect if it were written:

ad_proc -public myProc {} {} {        
    uplevel {
        Some Code Using X_var
    }
}
Collapse
Posted by Nis Jørgensen on
Samer, your example works fine with me. For instance:

ad_proc -public myProc {Var} {} {
        upvar X_var vv_var
        set vv_var $Var
        uplevel {
          set Y_var "${X_var}bar"
        }
}

myProc "foo"
set Y_var


returns "foobar" just as it should.
Collapse
Posted by Tom Jackson on

To answer your question if this is the most right solution: no it isn't. The use of uplevel/upvar is very application specific, and your example is about as far away from needing either of these features (and you use both), that you can get. If you have the actual code you want to run, then show us that so we can offer more a realistic assessment. Maybe start by reading the manual entry for uplevel/upvar.