lua-users home
lua-l archive

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


Is there a way I can pass line by line of a script to Lua.  I've tried the 
example interpreter in Listing 24.1 of PIL2 but if the syntax element 
continues over more than one line, then an error is reported.  Lua is 
supposed to detect when the line it has read does not form a complete chunk 
and ask for more - p4 of PIL2.  Is there a way I can do this from my own 
loop to read a line at a time.  My current read thru the script file looks 
like:

    ...
    while(templateFile) {
        templateFile.getline(buff, BUFSIZ);
        // ?? debug echo to the console
        fprintf(stdout, "%s\n", buff);
        iError = luaL_loadbuffer(L, buff, strlen(buff), "Line")
            || 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;
        }
    }
    lua_close(L);

Doing it this way the line numbers are incorrect in the error messages as 
well but that's easy to fix.  But I'd really like to read the file myself, 
line by line if it's possible.

Ed
--
Edward E.L. Mitchell
Phone: (239)415-7039
6707 Daniel Court
Fort Myers, FL 33908