|
On 2012-11-03 5:21 AM, "Xavier Wang" <weasley.wx@gmail.com> wrote:
>
> Hi list,
>
> this morning I'm writing a Lua script converting UnicodeData.txt from
> unicode.org to a C file, just like the one slnunicode used. I just
> want to refactor slnunicode, make it simpler, smaller and fit Lua 5.2.
>
> After dig enough information from text database, I use a variable
> "line" to contain a line ready to write to C file, just like this:
>
> ----------------
> local line = " "
> local lastv
> for i, v in ipairs(pages) do
> --io.write("page["..i.."] = {"..table.concat(v, ", ").."}\n")
> if i == lastpage+1 then
> io.write(line:gsub(1, -3), "\n")
> line = " ,"
> io.write "#if UTF_MAX > 3\n"
> end
> for _, v in ipairs(v) do
> line = line .. (v-1) .. ", "
> if #line > 70 then
> io.write(line:sub(1, -2), "\n")
> line = " "
> end
> end
> lastv = v
> end
> io.write(line:sub(1, -3), "\n")
> io.write [[
> #endif /* UTF_MAX > 3 */
> };
> ]]
>
> -------------------
>
> just a part of script, did you see the issue in it? I don't. I just
> find, all output data are correct, except the one above "#if UTF_MAX
> >3" line -- some group index turned to negative number!!
>
> So I find in the algorithm to detect whether something I made it
> wrong, but no luck, I tried every thing I have thought, but no lucky.
> just the moment my computer get sucks, it run out all memory (4G) but
> taskmgr.exe tell me no program use many memory.... sigh, so I guess
> it's something wrong in Emergency garbage collector, so I close my
> computer and going to sleep.
>
> After a enough sleep (waked up my be girlfriend's call), I'm trying
> again to find out the issue. I boot my computer and everything the
> same, so it can't the issue of garbage collector, so I copy code to a
> fresh Lua script, and try to analyze it. it just output negative
> number as the same. at last I try to write a small script only output
> one line: it works! so it's the time to compare the two version of
> snippet...
>
> OH MY GOD!!!!
>
> Yes, maybe you have found out the answer. there is nothing wrong with
> my algorithm, nothing wrong with pretty print loop, the issue is just,
> I need use "sub" on line, but not "*g*sub"!!
>
> God bless coders stay up all night T-T
>
> the lesson I have learned:
> - Don't make simple thing complicate.
> - go to bed and have a *good* sleep before you work.
> - hi Roberto, when can we disable Auto Coercion? (Yes I know it's all
> my bad, but make a Lua don't have auto coercion will make life easy)
>
> Thanks for everybody interesting my unfortunate accident :-) God bless you!
>
> --
> regards,
> Xavier Wang.
>
It might be interesting to be able to turn off coercion temporarily by the debug library.
As for silly bugs, I think my favorite was a script that insisted its input file was empty. I debugged it for about half an hour before realizing that it was telling the truth.
Always make sure it's the program that's wrong, and not you... :)