lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Patrick,

Your example function two() doesn't return anything useful, it just
prints "blah" outright. I assume you wanted return "blah". Anyways,
you would likely want to define the function before you start
concatenation:

------
function one()
  local two = function()
    return "blah"
  end
  print[[long long string]] .. two() .. [[more of the long string]]
end
------

If the inner function is used frequently and is not used as a closure
with upvalues, you might want to define 'two' entirely separately from
'one', so you don't create a new function every time one() is run.

You can also embed the function directly within the string, which is
what I think you were going for. I don't recommend it generally,
because it's not terribly clear and has no benefits over the previous
example, but here you go:

------
function one()
  print([[long long string]] .. (function() return "blah" end)() ..
[[more of the long string]])
end
------

Notice that I wrapped the whole function() ... end block in
parentheses, and didn't give it a name. I also added () at the end of
it in order to actually call the function defined there.

~Jonathan

On Thu, Feb 11, 2010 at 10:37 AM, Patrick
<spell_gooder_now@spellingbeewinnars.org> wrote:
> Hi Everyone
>
> The level of expertise is very high on this list and I am well below the
> median but if someone could lend this dummy a hand that would be great.
>
> I am trying make a piece of code like this work.
>
> function one() print[[long long string]]  .. function two() print('blah')
> end two() .. [[more of the long string]] end
>
> I can't seem to figure out the correct parenthesis to allow the nested
> function to be concatenated between the two long strings.
>
> Thanks for reading-Patrick
>
>