[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: concatenation with nested functions
- From: Jonathan Castello <solugon@...>
- Date: Thu, 11 Feb 2010 10:47:54 -0800
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
local two = function()
print[[long long string]] .. two() .. [[more of the long string]]
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:
print([[long long string]] .. (function() return "blah" end)() ..
[[more of the long string]])
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.
On Thu, Feb 11, 2010 at 10:37 AM, Patrick
> 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