seqlua

diff seqlua.c @ 57:da4b9d6a5b7e

Fixed bug due to problem combining luaL_buffinit with seqlua_iterinit
author jbe
date Tue Jan 05 04:26:49 2016 +0100 (2016-01-05)
parents 92ce3958aca7
children
line diff
     1.1 --- a/seqlua.c	Wed Aug 27 00:31:43 2014 +0200
     1.2 +++ b/seqlua.c	Tue Jan 05 04:26:49 2016 +0100
     1.3 @@ -71,19 +71,25 @@
     1.4  static int seqlua_concat(lua_State *L) {
     1.5    const char *sep;
     1.6    size_t seplen;
     1.7 -  luaL_Buffer buf;
     1.8    seqlua_Iterator iter;
     1.9 +  // NOTE: the following implementation is inefficient (Lua buffer would
    1.10 +  //       prohibit use of stack by seqlua_iterloop)
    1.11    sep = luaL_checklstring(L, 1, &seplen);
    1.12    luaL_checkany(L, 2);
    1.13 -  lua_settop(L, 3);
    1.14 -  luaL_buffinit(L, &buf);
    1.15 +  lua_settop(L, 2);
    1.16 +  lua_pushliteral(L, "");
    1.17    seqlua_iterloop(L, &iter, 2) {
    1.18 -    lua_replace(L, 3);
    1.19 -    if (seqlua_itercount(&iter) > 1) luaL_addlstring(&buf, sep, seplen);
    1.20 -    luaL_tolstring(L, 3, NULL);
    1.21 -    luaL_addvalue(&buf);
    1.22 +    if (seqlua_itercount(&iter) > 1) {
    1.23 +      lua_pushvalue(L, 3);
    1.24 +      lua_pushlstring(L, sep, seplen);
    1.25 +      lua_pushvalue(L, -3);
    1.26 +      lua_concat(L, 3);
    1.27 +      lua_replace(L, 3);
    1.28 +      lua_pop(L, 1);
    1.29 +    } else {
    1.30 +      lua_replace(L, 3);
    1.31 +    }
    1.32    }
    1.33 -  luaL_pushresult(&buf);
    1.34    return 1;
    1.35  }
    1.36  

Impressum / About Us