lua-users home
lua-l archive

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

Hi list,

this morning I'm writing a Lua script converting UnicodeData.txt from 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"
    for _, v in ipairs(v) do
        line = line .. (v-1) .. ", "
        if #line > 70 then
            io.write(line:sub(1, -2), "\n")
            line = "    "
    lastv = v
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


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!

Xavier Wang.