From 26841296ab9e5f6d5df1a720e185334d5e84936b Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 28 Sep 2012 17:29:17 +0200 Subject: [PATCH] From Lua 5.2: Add table.pack(). Needs -DLUAJIT_ENABLE_LUA52COMPAT. --- src/lib_table.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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) return 0; } +#if LJ_52 +LJLIB_PUSH("n") +LJLIB_CF(table_pack) +{ + TValue *array, *base = L->base; + MSize i, n = (uint32_t)(L->top - base); + GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1); + /* NOBARRIER: The table is new (marked white). */ + setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n); + for (array = tvref(t->array) + 1, i = 0; i < n; i++) + copyTV(L, &array[i], &base[i]); + settabV(L, base, t); + L->top = base+1; + lj_gc_check(L); + return 1; +} +#endif + /* ------------------------------------------------------------------------ */ #include "lj_libdef.h"