seqlua

diff seqlua.c @ 25:44880bcfc323

Macro seqlua_iterloop doesn't automatically pop the value anymore (use seqlua_iterloopauto instead); New function string.concat(sep, seq) introduced
author jbe
date Thu Aug 21 21:32:01 2014 +0200 (2014-08-21)
parents 29792283522f
children 367fc70acc15
line diff
     1.1 --- a/seqlua.c	Thu Aug 21 20:20:20 2014 +0200
     1.2 +++ b/seqlua.c	Thu Aug 21 21:32:01 2014 +0200
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <lua.h>
     1.5  #include <lauxlib.h>
     1.6 +#include "seqlualib.h"
     1.7  
     1.8  static int seqlua_ipairsaux_raw(lua_State *L) {
     1.9    lua_Integer i;
    1.10 @@ -51,8 +52,30 @@
    1.11    return 3;
    1.12  }
    1.13  
    1.14 +static int seqlua_concat(lua_State *L) {
    1.15 +  const char *sep;
    1.16 +  size_t seplen;
    1.17 +  luaL_Buffer buf;
    1.18 +  seqlua_Iterator iter;
    1.19 +  sep = luaL_checklstring(L, 1, &seplen);
    1.20 +  luaL_checkany(L, 2);
    1.21 +  lua_settop(L, 3);
    1.22 +  luaL_buffinit(L, &buf);
    1.23 +  seqlua_iterloop(L, &iter, 2) {
    1.24 +    lua_replace(L, 3);
    1.25 +    if (seqlua_itercount(&iter) > 1) luaL_addlstring(&buf, sep, seplen);
    1.26 +    luaL_tolstring(L, 3, NULL);
    1.27 +    luaL_addvalue(&buf);
    1.28 +  }
    1.29 +  luaL_pushresult(&buf);
    1.30 +  return 1;
    1.31 +}
    1.32 +
    1.33  int luaopen_seqlua(lua_State *L) {
    1.34    lua_pushcfunction(L, seqlua_ipairs);
    1.35    lua_setglobal(L, "ipairs");
    1.36 -  return 1;
    1.37 +  lua_getglobal(L, "string");
    1.38 +  lua_pushcfunction(L, seqlua_concat);
    1.39 +  lua_setfield(L, -2, "concat");
    1.40 +  return 0;
    1.41  }

Impressum / About Us