lua-users home
lua-l archive

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


>I recently wanted to create an error message in C.
>Rather than mess about in C concatenating bits of strings, I decided
>to push the strings onto the stack, lua_concat() them, and then
>call lua_error(L, lua_tostring(L, -1)).
>
>Is that:
>	(a) Safe?

Yes.

>	(b) The most efficient way?

Depends on what you call "efficient".
It's certainly the most efficient in terms of your time.
Plus it avoids the hassle of memory allocation and the limitation of fixed-size
buffers.

String concatenation is one of the services that Lua provides, which is
independent of the fact that is a full language.
Other services like that are hash tables and expression evaluation.
--lhf