[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua and C strings
- From: "Evan DeMond" <evan.demond@...>
- Date: Mon, 20 Oct 2008 09:34:57 -0400
On Mon, Oct 20, 2008 at 9:28 AM, Jeff Wise <firstname.lastname@example.org>
I have some Lua code like:
This code works just fine. I later process the resultant file with multiple
C programs, and I am having difficulty. All three writes are string values,
but the lack of a NULL character at the end seems to SOMETIMES cause grief.
I haven't figured out this C problem yet. Is it a good programming practice
to use the statement below instead of the above?
The C programs sometimes correctly get the string lengths and other times do
not. I haven't discovered a pattern to this failure, but my C expertise is
about the same as my Lua level. For example, if "name1" were X'6162630A0D'
(as verified with a hex editor), should this instead be X'616263000A0D'?
(This is Win/XP). If you look at the Lua-produced file with Notepad or
SCiTE, it looks as one would expect. The specific problem occurs when
"name2" is a dummy value, which I have assigned as "^??^". The C error seems
to be that "name1" and "name2" are read as a single line instead of two
I wouldn't write zeroes into your strings from the Lua code just to satisfy some C programs - if someone's reading only the Lua code, it's puzzling. I'd just write the strings plainly from Lua, then figure out how to tackle this problem from the C end.
Nothing's immediately springing to mind there, but if the standard library functions to read a line of text aren't catching your dummy values correctly, perhaps you could look for a dummy value that does workr?