compiling lua

Carlos carlos-smith at sympatico.ca
Tue Sep 23 13:41:28 PDT 2008


: I think so too.

Yep, DMC does not support pipes on Windows.
After some more test, i found that lua read the pipe with fgets().
When reading the last line of input from the pipe, Windows
returns and error and set errno to 32 (EPIPE).
The DMC runtime does not properly process that error.

Now, if you want to have _popen/_pclose support,
you need to use _Popen/_Pclose and fix liolib.c file.

And the program works fine now.

I have batch file that produce a static lib of lua runtime if you
are interested.

Carlos

--- liolib.c fix ---

static int read_line (lua_State *L, FILE *f) {
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  for (;;)
  { size_t l;
    char *p = luaL_prepbuffer(&b);
    if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) /* eof? */
    { luaL_pushresult(&b);  /* close buffer */
      #ifdef __DMC__
      if( ferror(f) ==  32 ) // 32 == EPIPE (Broken pipe)
        clearerr(f);
      #endif
      return (lua_objlen(L, -1) > 0);  /* check whether read something */
    }

    #ifdef __DMC__
    if( ferror(f) ==  32 ) // 32 == EPIPE (Broken pipe)
      clearerr(f);
    #endif

    l = strlen(p);
    if (l == 0 || p[l-1] != '\n')
      luaL_addsize(&b, l);
    else {
      luaL_addsize(&b, l - 1);  /* do not include `eol' */
      luaL_pushresult(&b);  /* close buffer */
      return 1;  /* read at least an `eol' */
    }
  }
}




More information about the Digitalmars-d-learn mailing list