lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yeah, I have an implementation of table.clear;
"In my extension of LUA, comments are as // not /**/"
I bet it performs better than  luaH_next, as Cloud Wu said, performance would be the KEY.


void luaH_clear(lua_State *L, Table *h) {
//need not to barrierback, because new value is NIL;
unsigned int i;
for (i = 0; i < h->sizearray; i++)
setnilvalue(&h->array[i]);
if (h->node != dummynode) {
Node *n, *limit = gnodelast(h);
for (n = gnode(h, 0); n < limit; n++)   //traverse hash part
setnilvalue(gval(n));
}
}

2017-07-04 14:31 GMT+08:00 云风 Cloud Wu <cloudwu@gmail.com>:

Dirk Laurie <dirk.laurie@gmail.com>于2017年7月4日周二 下午12:38写道:
> If lua can offer a C API like lua_clonetable would be better ?

Let's get this straight: you are not offering code that relies on

#include <lobject.h>
#include <ltable.h>

And lgc.h lstate.h, I forgot call barrierback just now.
 
as if doing so is kosher; you are merely providing proof-of-concept
code that the requested feature lua_clonetable is possible, right?

 
 Yes.

lua_clonetable can be implement by lua_next, but the performance would be must better. And I think it would be very useful.

I remember Roberto said they were considering a table.clear function ( http://lua-users.org/lists/lua-l/2013-11/msg00669.html ) , we can use table.clone(tbl, {}) to instead of it.