aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2012-09-28 17:29:17 +0200
committerMike Pall <mike>2012-09-28 17:29:17 +0200
commit26841296ab9e5f6d5df1a720e185334d5e84936b (patch)
tree69e6c9cec73988b8341b6518166a5f93dfc4323f /src
parente013206dd845861c2e27766ada75a98501033cfd (diff)
downloadluajit-26841296ab9e5f6d5df1a720e185334d5e84936b.tar.gz
luajit-26841296ab9e5f6d5df1a720e185334d5e84936b.tar.bz2
luajit-26841296ab9e5f6d5df1a720e185334d5e84936b.zip
From Lua 5.2: Add table.pack(). Needs -DLUAJIT_ENABLE_LUA52COMPAT.
Diffstat (limited to 'src')
-rw-r--r--src/lib_table.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib_table.c b/src/lib_table.c
index 25894eb0..00374c60 100644
--- a/src/lib_table.c
+++ b/src/lib_table.c
@@ -266,6 +266,24 @@ LJLIB_CF(table_sort)
266 return 0; 266 return 0;
267} 267}
268 268
269#if LJ_52
270LJLIB_PUSH("n")
271LJLIB_CF(table_pack)
272{
273 TValue *array, *base = L->base;
274 MSize i, n = (uint32_t)(L->top - base);
275 GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1);
276 /* NOBARRIER: The table is new (marked white). */
277 setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n);
278 for (array = tvref(t->array) + 1, i = 0; i < n; i++)
279 copyTV(L, &array[i], &base[i]);
280 settabV(L, base, t);
281 L->top = base+1;
282 lj_gc_check(L);
283 return 1;
284}
285#endif
286
269/* ------------------------------------------------------------------------ */ 287/* ------------------------------------------------------------------------ */
270 288
271#include "lj_libdef.h" 289#include "lj_libdef.h"