diff options
author | Mike Pall <mike> | 2013-10-09 17:01:22 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-10-09 17:02:01 +0200 |
commit | c8cfca05578932567d2c65d59262f398e8acaed2 (patch) | |
tree | 5699e7f2df3a5166eee667b0971775cea6c0ab4b /src/lib_table.c | |
parent | 47df3ae5136521da96767e6daed4cdd241de2fa6 (diff) | |
download | luajit-c8cfca05578932567d2c65d59262f398e8acaed2.tar.gz luajit-c8cfca05578932567d2c65d59262f398e8acaed2.tar.bz2 luajit-c8cfca05578932567d2c65d59262f398e8acaed2.zip |
Add table.new().
Diffstat (limited to 'src/lib_table.c')
-rw-r--r-- | src/lib_table.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib_table.c b/src/lib_table.c index d7df8399..85ca660e 100644 --- a/src/lib_table.c +++ b/src/lib_table.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include "lj_err.h" | 18 | #include "lj_err.h" |
19 | #include "lj_buf.h" | 19 | #include "lj_buf.h" |
20 | #include "lj_tab.h" | 20 | #include "lj_tab.h" |
21 | #include "lj_ff.h" | ||
21 | #include "lj_lib.h" | 22 | #include "lj_lib.h" |
22 | 23 | ||
23 | /* ------------------------------------------------------------------------ */ | 24 | /* ------------------------------------------------------------------------ */ |
@@ -264,6 +265,24 @@ LJLIB_CF(table_pack) | |||
264 | } | 265 | } |
265 | #endif | 266 | #endif |
266 | 267 | ||
268 | LJLIB_NOREG LJLIB_CF(table_new) LJLIB_REC(.) | ||
269 | { | ||
270 | int32_t a = lj_lib_checkint(L, 1); | ||
271 | int32_t h = lj_lib_checkint(L, 2); | ||
272 | lua_createtable(L, a, h); | ||
273 | return 1; | ||
274 | } | ||
275 | |||
276 | static int luaopen_table_new(lua_State *L) | ||
277 | { | ||
278 | GCfunc *fn = lj_lib_pushcc(L, lj_cf_table_new, FF_table_new, 0); | ||
279 | GCtab *t = tabref(curr_func(L)->c.env); /* Reference to "table". */ | ||
280 | setfuncV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "new")), fn); | ||
281 | lj_gc_anybarriert(L, t); | ||
282 | setfuncV(L, L->top++, fn); | ||
283 | return 1; | ||
284 | } | ||
285 | |||
267 | /* ------------------------------------------------------------------------ */ | 286 | /* ------------------------------------------------------------------------ */ |
268 | 287 | ||
269 | #include "lj_libdef.h" | 288 | #include "lj_libdef.h" |
@@ -275,6 +294,7 @@ LUALIB_API int luaopen_table(lua_State *L) | |||
275 | lua_getglobal(L, "unpack"); | 294 | lua_getglobal(L, "unpack"); |
276 | lua_setfield(L, -2, "unpack"); | 295 | lua_setfield(L, -2, "unpack"); |
277 | #endif | 296 | #endif |
297 | lj_lib_prereg(L, LUA_TABLIBNAME ".new", luaopen_table_new, tabV(L->top-1)); | ||
278 | return 1; | 298 | return 1; |
279 | } | 299 | } |
280 | 300 | ||