lua-users home
lua-l archive

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


Enrico Colombini wrote:
/snip
> I see two problems here:
> - first, newlines are inserted in the string. I can't tell them
>   from those I inserted as '\n'.
> - second, if I indent my text for better reading, spaces are
>   added at the beginning of each line.
> 
/snip

To solve these problems you can:
- use <br> in stead of \n. Postprocess with gsub.
- trim away the excess spaces. Gsun is again useful there. 

This is how you can do it in Lua itself:

aid = gsub(description, "%s+", " ")
description = gsub(aid, "<br>", "\n"))

It may be more performant to do this kind of postprocessing
in C. If you really wat top n,otch performance, you could customise the 
Lua parser so multiple spaces are seen as a single one when parsing a 
long string. 

> Didn't he refer to Lua 5.0? I am still planning to use 4.0, and I already
> encountered the slow concatenation problem in another application (saving a
> large and complex table to a string took minutes).

Yes, sorry, I misunderstood. However, string concatenation
is slow in many scripting languages. I doubt VB is that much faster 
than Lua in this aspect. This is a performance problem that may 
need some extra attention, but has no easy solution. 


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be