Hi!
----
[Per offlist request for a "typeset -m" demo...]
Below is a small code example how an stack for ksh93 variable objects
can be implemented:
-- snip --
# stack of objects
typeset -T objstack_t=(
compound -a st
integer st_n=0
# push an object
# argument is the name of a variable which will
# be moved into the stack space
function pushobj
{
nameref obj=$1
typeset -m "_.st[$((_.st_n++))].obj=obj"
}
# print absolute variable name of object in head
function printhead
{
printf '%s%s\n' "${!_}" ".st[${_.st_n}].obj"
}
# pop an object and return it to the location
# specified by the variable name passed in
function popobj
{
nameref obj=$1
typeset -m "obj=_.st[$((--_.st_n))].obj"
}
)
function main
{
compound c
objstack_t c.ost
# push some objects
compound foo=( integer val=5 )
compound bar=( integer val=6 )
typeset -A bok=( [a]=11 [b]=22 [c]=33 )
typeset -a baz=( 2 3 4 )
typeset -a baz2
baz2[2][2]=4
baz2[2][4]=8
baz2[3][2]=6
baz2[3][4]=12
c.ost.pushobj foo
c.ost.pushobj bar
c.ost.pushobj bok
c.ost.pushobj baz2
c.ost.pushobj baz
#c.ost.printhead
# get object from stack head and store it
# in compound variable "popc.store"
compound popc
c.ost.popobj popc.store
print -v popc
return 0
}
set -o nounset
main
-- snip --
The code will print:
-- snip --
$ ksh objstackdemo1.sh
(
typeset -a store=(
2
3
4
)
)
-- snip --
Erm... have fun... :-)
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users