diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-06 11:15:22 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-06 11:15:22 +0100 |
commit | 9d78ee372d9d4db601098d4d302df48159d7b176 (patch) | |
tree | a00fa6e59c74d4e4ded1c00adbbf510d156aa768 /src/lstrlib.js | |
parent | c3c1ab50646165c0e43784acb30a353dc5b40d12 (diff) | |
download | fengari-9d78ee372d9d4db601098d4d302df48159d7b176.tar.gz fengari-9d78ee372d9d4db601098d4d302df48159d7b176.tar.bz2 fengari-9d78ee372d9d4db601098d4d302df48159d7b176.zip |
string.rep
Diffstat (limited to 'src/lstrlib.js')
-rw-r--r-- | src/lstrlib.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js index 96a33f5..11b266a 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -35,10 +35,20 @@ const str_upper = function(L) { return 1; }; +const str_rep = function(L) { + let s = lauxlib.luaL_checkstring(L, 1); + let n = lauxlib.luaL_checkinteger(L, 2); + let sep = lauxlib.luaL_optstring(L, 3, ""); + + lapi.lua_pushstring(L, (s + sep).repeat(n - 1) + s); + return 1; +}; + const strlib = { "char": str_char, "len": str_len, "lower": str_lower, + "rep": str_rep, "upper": str_upper }; |