Why using stack?

9 views
Skip to first unread message

stej

unread,
May 5, 2010, 5:44:27 PM5/5/10
to psake-dev
I see [system.collections.stack]$script:context defined at the
beginning of psake.psm1.
The only reason why one would need stack is because of nested callings
of invoke-psake, right? Or am I missing something?

If so, it could be probably possible to let just call stack work for
us. Variables are retrieved in a dynamic way, so if each Invoke-Psake
would define its context, it should work.

Example:
function wrapper1 {
$Test = 'wrapper1'
wrapper2
}

function wrapper2 {
wrapper3
}

function wrapper3 {
$Test = 'wrapper3'
variablegetter
}

function variablegetter {
write-host Retrieving all variables names Test
0..4 | % { Get-Variable Test -scope $_ -ea 0 } | ft -auto *
}
wrapper1

-----returns-------
Name Description Value Visibility Module ModuleName Options
Attributes
---- ----------- ----- ---------- ------ ---------- -------
----------
Test wrapper3 Public None
{}
Test wrapper1 Public None {}

--
You received this message because you are subscribed to the Google Groups "psake-dev" group.
To post to this group, send email to psak...@googlegroups.com.
To unsubscribe from this group, send email to psake-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psake-dev?hl=en.

James Kovacs

unread,
May 9, 2010, 11:59:40 PM5/9/10
to psak...@googlegroups.com
The context stack is for nested callings of invoke-psake. I would have to look into the details more to know why we needed the context stack. I believe Jorge was the one who implemented this and would know more. Ideas, Jorge?

BTW - If you're going to try changing this, make sure that there is a test around nested invoke-psake calls. There should be, but let's make sure we're not breaking anything...

James
--
James Kovacs, B.Sc., M.Sc., MCSD, MCT
Microsoft MVP, ASP/ASP.NET
http://www.jameskovacs.com
jko...@post.harvard.edu | @jameskovacs
403-397-3177 (mobile)

stej

unread,
May 19, 2010, 4:55:19 AM5/19/10
to psake-dev
Figured out, that it is not as easy as it looked like.
The reason is that dot sourcing is heavily used and thus it operates
in a shared scope.

I'll have a look at it more closely later and hopefully write a blog
post about the scoping ;)

Jorge

unread,
May 30, 2010, 4:01:54 PM5/30/10
to psake-dev
stej,

Sorry for the late reply, but the stack was the only way I could
implement nested builds - but it appears you've already come to the
same conclusion. If you can think of a better or easier
implementation then please don't hesitate to let us know.
Reply all
Reply to author
Forward
0 new messages