lua-users home
lua-l archive

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


2014-08-02 2:34 GMT+08:00 Coroutines <coroutines@gmail.com>:
> On Fri, Aug 1, 2014 at 11:10 AM, Coda Highland <chighland@gmail.com> wrote:
>
>> Seriously, though, I can't see any real uses for it beyond just a
>> complete and total table wipe. Anything else is either adequately
>> served by nil assignment, or is an implementation detail that isn't
>> exposed anyway.
>>
>> /s/ Adam
>>
>
> Yeah, just a simple clear() for everything in the table would be nice.
> I don't know exactly how the array-part or the hash-part work but
> ideally I'd want a tight C loop on both to nil their values and set
> the length for either portion -- so the allocated array internally
> says the same size, it's just cleared.  Same for the hash portion.
>
> I could really only see extra parameters to this function if I wanted
> to clear only the array portion, or only the hash portion.
>
> Something like: table.clear(table[, mode]) -- were mode is a string
> containing either 'a' for array or 'h' for hash -- similar to __mode's
> option list in metatables.  Really just a table.clear() for erasing
> everything would be nice...
>

Yes, and if do this in C API it may even better.

void lua_wipetable(lua_State *L, int arraypart, int hashpart);

core will not use lua_next, but some tight C loop just set all key and
value to nil - that may easy in core.

-- 
regards,
Xavier Wang.