# HG changeset patch # User jbe # Date 1429028439 -7200 # Node ID e0ab9fd00cb1a4e892584c09d58f590d08358497 # Parent d9cc81641175906c6f3d71abf59b07bebda52288 Removed :readuntil(...) function diff -r d9cc81641175 -r e0ab9fd00cb1 moonbridge.c --- a/moonbridge.c Tue Apr 14 00:26:38 2015 +0200 +++ b/moonbridge.c Tue Apr 14 18:20:39 2015 +0200 @@ -1755,46 +1755,6 @@ return ptr; } -/* New method for Lua file objects: read until terminator or length exceeded */ -static int moonbr_readuntil(lua_State *L) { - luaL_Stream *stream; - FILE *file; - const char *terminatorstr; - size_t terminatorlen; - luaL_Buffer buf; - lua_Integer maxlen; - char terminator; - int byte; - stream = luaL_checkudata(L, 1, LUA_FILEHANDLE); - terminatorstr = luaL_checklstring(L, 2, &terminatorlen); - luaL_argcheck(L, terminatorlen == 1, 2, "single byte expected"); - maxlen = luaL_optinteger(L, 3, 0); - if (!stream->closef) luaL_error(L, "attempt to use a closed file"); - file = stream->f; - luaL_buffinit(L, &buf); - if (!maxlen) maxlen = -1; - terminator = terminatorstr[0]; - while (maxlen > 0 ? maxlen-- : maxlen) { - byte = fgetc(file); - if (byte == EOF) { - if (ferror(file)) { - char errmsg[MOONBR_MAXSTRERRORLEN]; - strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN); /* use thread-safe call in case child created threads */ - lua_pushnil(L); - lua_pushstring(L, errmsg); - return 2; - } else { - break; - } - } - luaL_addchar(&buf, byte); - if (byte == terminator) break; - } - luaL_pushresult(&buf); - if (!lua_rawlen(L, -1)) lua_pushnil(L); - return 1; -} - static int moonbr_lua_tonatural(lua_State *L, int idx) { int isnum; lua_Number n; @@ -2314,14 +2274,6 @@ #ifdef MOONBR_LUA_CPATH moonbr_modify_path(L, "cpath", MOONBR_LUA_CPATH); #endif - if (luaL_newmetatable(L, LUA_FILEHANDLE)) { - moonbr_log(LOG_CRIT, "Lua metatable LUA_FILEHANDLE does not exist"); - moonbr_terminate_error(); - } - lua_getfield(L, -1, "__index"); - lua_pushcfunction(L, moonbr_readuntil); - lua_setfield(L, -2, "readuntil"); - lua_pop(L, 2); lua_pushcfunction(L, moonbr_timeout); lua_setglobal(L, "timeout"); lua_pushcfunction(L, moonbr_listen);