lua-users home
lua-l archive

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



A simple C-implemented 'string.concat()', or 'stringlet()' would have all the benefits:

	output( string.let( "foo", "bar", "baz" ) )

It could first count lengths of all the parameters, then append them directly to a single output string. No interim strings, no tables ( table.concat{...} does the same, but with interim table ).

Of course, the best would be if the Lua parser is capable of making consecutive concat's into a single '__concat()' method call (with multiple arguments). This kind of optimization would actually be agreeable to Lua authors, I think (not that I'm in any position to say what they like.. :)

-ak


20.4.2005 kello 15:44, Mike Pall kirjoitti:

 Hi,

Gavin Wraith wrote:
If the final string is actually needed, that is clearly the way to go.
In practice, it very rarely is needed. Usually the rope/stringle (sorry "stringle" was an extemporization) gets written out to a file. The point is that ropes are very easy to program in Lua. I doubt whether managing
them at the C level gains one very much.

Generally design I/O functions in C to handle both multiple
arguments and nested tables from Lua. Very easy to work with
on the Lua side. And fast, too.

Example:

output("foo".."bar".."baz")      -- Slow. Avoid single arg I/O APIs.

output("foo", "bar", "baz")      -- Allow multiple arguments.
output{"foo", "bar", "baz"}      -- Allow tables.
output({"foo", {"bar"}}, "baz") -- Allow nested tables. Mixing args is ok.

Bye,
     Mike