| 1997 | |
| 1998 | |
| 1999 | static int foldcap (CapState *cs) { |
| 2000 | int n; |
| 2001 | lua_State *L = cs->L; |
| 2002 | int idx = cs->cap->idx; |
| 2003 | if (isfullcap(cs->cap++) || isclosecap(cs->cap) || (n = pushcapture(cs)) == 0) |
| 2004 | return luaL_error(L, "no initial value for fold capture"); |
| 2005 | if (n > 1) |
| 2006 | lua_pop(L, n - 1); /* leave only one result */ |
| 2007 | while (!isclosecap(cs->cap)) { |
| 2008 | updatecache(cs, idx); |
| 2009 | lua_pushvalue(L, subscache(cs)); /* get folding function */ |
| 2010 | lua_insert(L, -2); /* put it before accumulator */ |
| 2011 | n = pushcapture(cs); /* get other captures */ |
| 2012 | lua_call(L, n + 1, 1); /* call folding function */ |
| 2013 | } |
| 2014 | cs->cap++; /* skip close entry */ |
| 2015 | return 1; |
| 2016 | } |
| 2017 | |
| 2018 | |
| 2019 | static int functioncap (CapState *cs) { |
no test coverage detected