From e7c2eebd87ac0241d346ae3ac01336708f0729c1 Mon Sep 17 00:00:00 2001
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 16 Oct 2001 15:41:43 -0200
Subject: new function `concat'

---
 lstrlib.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/lstrlib.c b/lstrlib.c
index 8c3892b0..fc27a6a4 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.69 2001/07/17 18:46:49 roberto Exp $
+** $Id: lstrlib.c,v 1.71 2001/08/31 19:46:07 roberto Exp $
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -87,6 +87,25 @@ static int str_rep (lua_State *L) {
 }
 
 
+static int str_concat (lua_State *L) {
+  luaL_Buffer b;
+  size_t lsep;
+  const char *sep = luaL_opt_lstr(L, 2, "", &lsep);
+  int n, i;
+  luaL_checktype(L, 1, LUA_TTABLE);
+  luaL_buffinit(L, &b);
+  n = lua_getn(L, 1);
+  for (i=1; i<=n; i++) {
+    lua_rawgeti(L, 1, i);
+    luaL_addvalue(&b);
+    if (i != n)
+      luaL_addlstring(&b, sep, lsep);
+  }
+  luaL_pushresult(&b);
+  return 1;
+}
+
+
 static int str_byte (lua_State *L) {
   size_t l;
   const l_char *s = luaL_check_lstr(L, 1, &l);
@@ -646,6 +665,7 @@ static const luaL_reg strlib[] = {
 {l_s("strchar"), str_char},
 {l_s("strrep"), str_rep},
 {l_s("strbyte"), str_byte},
+{l_s("concat"), str_concat},
 {l_s("format"), str_format},
 {l_s("strfind"), str_find},
 {l_s("gsub"), str_gsub}
-- 
cgit v1.2.3-55-g6feb