moonbridge

changeset 126:e0ab9fd00cb1

Removed <file>:readuntil(...) function
author jbe
date Tue Apr 14 18:20:39 2015 +0200 (2015-04-14)
parents d9cc81641175
children 37532927dba9
files moonbridge.c
line diff
     1.1 --- a/moonbridge.c	Tue Apr 14 00:26:38 2015 +0200
     1.2 +++ b/moonbridge.c	Tue Apr 14 18:20:39 2015 +0200
     1.3 @@ -1755,46 +1755,6 @@
     1.4    return ptr;
     1.5  }
     1.6  
     1.7 -/* New method for Lua file objects: read until terminator or length exceeded */
     1.8 -static int moonbr_readuntil(lua_State *L) {
     1.9 -  luaL_Stream *stream;
    1.10 -  FILE *file;
    1.11 -  const char *terminatorstr;
    1.12 -  size_t terminatorlen;
    1.13 -  luaL_Buffer buf;
    1.14 -  lua_Integer maxlen;
    1.15 -  char terminator;
    1.16 -  int byte;
    1.17 -  stream = luaL_checkudata(L, 1, LUA_FILEHANDLE);
    1.18 -  terminatorstr = luaL_checklstring(L, 2, &terminatorlen);
    1.19 -  luaL_argcheck(L, terminatorlen == 1, 2, "single byte expected");
    1.20 -  maxlen = luaL_optinteger(L, 3, 0);
    1.21 -  if (!stream->closef) luaL_error(L, "attempt to use a closed file");
    1.22 -  file = stream->f;
    1.23 -  luaL_buffinit(L, &buf);
    1.24 -  if (!maxlen) maxlen = -1;
    1.25 -  terminator = terminatorstr[0];
    1.26 -  while (maxlen > 0 ? maxlen-- : maxlen) {
    1.27 -    byte = fgetc(file);
    1.28 -    if (byte == EOF) {
    1.29 -      if (ferror(file)) {
    1.30 -        char errmsg[MOONBR_MAXSTRERRORLEN];
    1.31 -        strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN);  /* use thread-safe call in case child created threads */
    1.32 -        lua_pushnil(L);
    1.33 -        lua_pushstring(L, errmsg);
    1.34 -        return 2;
    1.35 -      } else {
    1.36 -        break;
    1.37 -      }
    1.38 -    }
    1.39 -    luaL_addchar(&buf, byte);
    1.40 -    if (byte == terminator) break;
    1.41 -  }
    1.42 -  luaL_pushresult(&buf);
    1.43 -  if (!lua_rawlen(L, -1)) lua_pushnil(L);
    1.44 -  return 1;
    1.45 -}
    1.46 -
    1.47  static int moonbr_lua_tonatural(lua_State *L, int idx) {
    1.48    int isnum;
    1.49    lua_Number n;
    1.50 @@ -2314,14 +2274,6 @@
    1.51  #ifdef MOONBR_LUA_CPATH
    1.52      moonbr_modify_path(L, "cpath", MOONBR_LUA_CPATH);
    1.53  #endif
    1.54 -    if (luaL_newmetatable(L, LUA_FILEHANDLE)) {
    1.55 -      moonbr_log(LOG_CRIT, "Lua metatable LUA_FILEHANDLE does not exist");
    1.56 -      moonbr_terminate_error();
    1.57 -    }
    1.58 -    lua_getfield(L, -1, "__index");
    1.59 -    lua_pushcfunction(L, moonbr_readuntil);
    1.60 -    lua_setfield(L, -2, "readuntil");
    1.61 -    lua_pop(L, 2);
    1.62      lua_pushcfunction(L, moonbr_timeout);
    1.63      lua_setglobal(L, "timeout");
    1.64      lua_pushcfunction(L, moonbr_listen);

Impressum / About Us