[carceri-dev] Re: Status Report (25 Aug 2005)

  • From: Timothy Pruett <drakalor.tourist@xxxxxxxxx>
  • To: carceri-dev@xxxxxxxxxxxxx
  • Date: Thu, 25 Aug 2005 00:03:40 -0400

Kornel Kisielewicz wrote:

Without any problems :-).... Well I have a personal problem -- it uses PChars (Zero terminated strings) because of the fact that it was translated from C, and I prefer usingf Strings ;-).

I'm paging through Lua's C API documentation, and it says that:
"Strings in Lua are not zero-terminated; in consequence, they can contain arbitrary binary data and rely on explicit length. The official function to push a string onto the stack is lua_pushlstring, which requires an explicit length as an argument. For zero-terminated string, you can use also lua_pushstring, which uses strlen to supply the string length."

I could be wrong, but I'm pretty sure that any string you create in a Lua script will not be zero-terminated. The problem, I believe, comes from the lua_tostring function, which gets the string from the stack. I think it automatically adds the zero to the end of the string, which seems somewhat silly. They have a way to push a non-zero-terminated string onto the stack, but they have no way to pop it back off. Strange, isn't it? ;-)

I guess you could shave the zero off yourself, but it doesn't really seem worth the effort.

Carceri Development Mailing List (carceri-dev@xxxxxxxxxxxxx)
Carceri Homepage (http://chaos.magma-net.pl/carceri)

Other related posts: