Error messages from C

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error messages from C

Daniel Silverstone
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?
	(b) The most efficient way?

Many thanks in advance.

Daniel


Reply | Threaded
Open this post in threaded view
|

Re: Error messages from C

Luiz Henrique de Figueiredo
>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