[albatross-users] al-for / ListIterator question...

Cameron Blackwood korg at darkqueen.org
Tue Oct 18 15:27:21 EST 2005



Hi,

Im using the albatross templater to generate C like code (actually,
its real usable C code, but thats beside the point)
something that i need some advice on.

I have a list of functions with inputs and outputs and im trying to
generate code that does something like:


-----------------------------
<al-for iter="ifun" expr="functions">
<al-exec expr="f=ifun.value()">

CALL_FUNCTION_<al-value expr="f.name">(
  # input1 , input2 , input3 , ... , inputN (NOCOMMA)
  <al-for iter="iarg" expr="f.inputs">
  <al-exec expr="a=iarg.value()">
      <al-value expr="a.arg_name" noescape>
      <al-if expr="iarg.index()  < len(f.inputs)-1">,</al-if whitespace>
  </al-for>

  # if inputs and outputs then , to seperate
  <al-if expr="len(f.inputs) >0">
   <al-if expr="len(f.outputs) >0">
     ,
   <al-if>
  <al-if>

  # output1 , output2 , output3 , ... , outputN (NOCOMMA)
  <al-for iter="oarg" expr="f.outputs">
  <al-exec expr="a=oarg.value()">
      <al-value expr="a.arg_name" noescape>
      <al-if expr="oarg.index()  < len(f.outputs)-1">,</al-if whitespace>
  </al-for>
  )

</al-for>
-----------------------------

to generate:

CALL_FUNCTION_foo(
  in1, in2, in3
  ,
  out1, out2
  )




But, for seperating arguments, the:

      <al-if expr="oarg.index()  < len(f.outputs)-1">,</al-if whitespace>

is ugly. I guess what im wanting is a oarg.has_next() or
oarg.is_last() or oarg.is_final(). 


The ways that I can think of to do it are:
  * abuse pagesize:
      <al-for iter="iarg" expr="f.inputs" pagesize="1">
    combined with:
      <al-if expr="oarg.has_nextpage()">,</al-if>

  * write my own tag:
    that might get around the need for the <al-exec expr="a=oarg.value()">
    too, especially if combined with...

  * put the 'is_last()' check into the actual objects


Hmm. Advice welcome. :-)


cheers,
cam

PS: I posted here about using albatross in the pyweek games contest..
sadly I got to distracted with pygame/graphics issues to get very far.
Oh well, next one is in feb ;)


--
 / `Rev Dr'   cam  at darkqueen.org            Roleplaying, virtual goth \
<   http://darkqueen.org        Poly, *nix, Python, C/C++, genetics, ATM  >
 \  [+61 3] 9809 1523[h]         skeptic, Evil GM(tm). Sysadmin for hire /
                      ---------- Random Quote ----------
"I'd crawl over an acre of 'Visual This++' and 'Integrated Development
That' to get to gcc, Emacs, and gdb.  Thank you."
(By Vance Petree, Virginia Power)



More information about the Albatross-users mailing list