# HG changeset patch # User jbe # Date 1451964409 -3600 # Node ID da4b9d6a5b7ea2dae8ee8c62be7b7f45d33a1d5a # Parent c3976eacc6ab13446cba1f61faed4553e191fcf7 Fixed bug due to problem combining luaL_buffinit with seqlua_iterinit diff -r c3976eacc6ab -r da4b9d6a5b7e seqlua.c --- a/seqlua.c Wed Aug 27 00:31:43 2014 +0200 +++ b/seqlua.c Tue Jan 05 04:26:49 2016 +0100 @@ -71,19 +71,25 @@ static int seqlua_concat(lua_State *L) { const char *sep; size_t seplen; - luaL_Buffer buf; seqlua_Iterator iter; + // NOTE: the following implementation is inefficient (Lua buffer would + // prohibit use of stack by seqlua_iterloop) sep = luaL_checklstring(L, 1, &seplen); luaL_checkany(L, 2); - lua_settop(L, 3); - luaL_buffinit(L, &buf); + lua_settop(L, 2); + lua_pushliteral(L, ""); seqlua_iterloop(L, &iter, 2) { - lua_replace(L, 3); - if (seqlua_itercount(&iter) > 1) luaL_addlstring(&buf, sep, seplen); - luaL_tolstring(L, 3, NULL); - luaL_addvalue(&buf); + if (seqlua_itercount(&iter) > 1) { + lua_pushvalue(L, 3); + lua_pushlstring(L, sep, seplen); + lua_pushvalue(L, -3); + lua_concat(L, 3); + lua_replace(L, 3); + lua_pop(L, 1); + } else { + lua_replace(L, 3); + } } - luaL_pushresult(&buf); return 1; } diff -r c3976eacc6ab -r da4b9d6a5b7e seqlualib.c --- a/seqlualib.c Wed Aug 27 00:31:43 2014 +0200 +++ b/seqlualib.c Tue Jan 05 04:26:49 2016 +0100 @@ -8,6 +8,8 @@ #define SEQLUA_ITERTYPE_INDEX 3 #define SEQLUA_ITERTYPE_RAW 4 +// TODO: allow combining luaL_buffinit with seqlua_iterinit somehow + void seqlua_iterinit(lua_State *L, seqlua_Iterator *iter, int idx) { if (luaL_getmetafield(L, idx, "__ipairs")) { lua_pushvalue(L, idx);