lua-users home
lua-l archive

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


"Rici Lake" <lua@ricilake.net> wrote in message 
de0b517e2d945e342c767922176483f6@ricilake.net">news:de0b517e2d945e342c767922176483f6@ricilake.net...
>
> On 17-Oct-06, at 8:38 PM, Edward Mitchell wrote:
>> As far as I can see, there's nothing like this in lua.c. It seems that
>> lua_load(...) (or luaL_loadbuffer) should return an status code that 
>> implies
>> "Needs more input."
>
> It returns a syntax error with an easily parseable error message, which is 
> what lua.c does. See the function incomplete() on line 161 (v5.1.1)
>
On that basis, it seems that I can use the loop like:

    while(templateFile) {
        templateFile.getline(buff, BUFSIZ);
        // ?? debug echo to the console
        fprintf(stdout, "%s\n", buff);
        while(Incomplete(L, luaL_loadbuffer(L, buff, strlen(buff), "Line"))) 
{
            templateFile.getline(buff, BUFSIZ);
        }
        iError = lua_pcall(L, 0, 0, 0);
        if(iError) {
            // echo the error message
            fprintf(stdout, "%s\n", lua_tostring(L, -1));
            // quit on any error
            break;
        }
    }

I looked at incomplete() and it seems to make a decision on whether the 
string <eof> is present in the error message.  Since incomplete() is not one 
of the lua_... or luaL_... group of routines, is it likely that the '<eof>' 
ending message will go away in the future.

However, I tried the above loop with the folowing input file:

for i = 1, 3 do
    print(i);
end

and got this output in the console window.

for i = 1, 3 do
nil
end

It looks like the parser is throwing away the knowledge that the for loop is 
not closed yet.  I built an interpreter some time ago and I had the parser 
return a special code that distinguished between and error and a need of 
more input to complete the sentence.  However, that also relied on a semi 
colon to terminate a statement, not needed in Lua.


My script is just a generator of html files like:

Put([[
<html><body>...many more lines
]])
for i=0, NumClass() then
    SelectClass(i); Process()
end
Put([[
</body></html>
]])

with more code segments and html text to make up the page.

Ed