lua-users home
lua-l archive

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

On 2015-06-24 2:38 AM, voidptr wrote:
On 2015-06-22 5:53 PM, Coda Highland wrote:
On Mon, Jun 22, 2015 at 2:37 PM, voidptr <> wrote:
Same noob on a working email this time :o)

On Wed, Jun 17, 2015 at 8:44 PM, Coda Highland <chighland at>
On Wed, Jun 17, 2015 at 7:56 PM, voidptr69 at
<voidptr69 at> wrote:
Another noob tought.

t = { "a", "b", "c" }
s = t:concat()   --  notworking same has s= t.concat(t)
s = Table.concat(t)

tables don't have metatable...
but why ? :o)

My guess is 99% of tables in script are used like a default table and
share Table by default..
And keep the short calling way valid is that case.

When you need to use tables for others purpose;
class base or prototype base languages, mockup object, other data
etc etc ...
you will need to define a metatable and add the others functions you need
constructor, copier, destructor ...)
so in those case you need to have an explicit constructor.

so why not offer by default, like for String, a metatable for table ?

voidptr :-)

If tables had metatables, then what data structure would you use to
make objects with customized behavior?

Tables are THE fundamental object type in Lua. Their entire purpose is
to be simple and generic enough to be able to do anything you want
with them.

well reread my message :-)
Has I said if you need another use for the table ex. build class or
prototype language forms,
or any kind of muckup objects you will surely, has you shown, build a
constructor function and
creating a link to some metatable using setmetatable.

But my question is still why not bind by default tables from the system to
Table ?
table are used most of the time as stanard dictionary /table in script :o)

I did read your message several times.

The whole point is that if you want to do something else with tables,
then you should add a metatable to the tables you want to do those
things with. Having a global metatable on tables like there is on
strings would get very messy -- note that Javascript allows you to do
this, and it breaks things quite visibly, so this isn't just a
theoretical concern.

/s/ Adam

Ok if you say so ...

ok this is maybe why it will be messy (my guest) , there is no distinction between user/script table and lua internal table... so in fact if you dont want to have metatable associate with _G or any other system tables, you just dont give it by default ...

I thought it could have been 2 ways to create table, clean system one, or with metatable for user ..

... so one size fit all, will not be the right size for all ... lol
too bad :o)



Table *luaH_new (lua_State *L) {
  GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
  Table *t = gco2t(o);
  t->metatable = NULL;
  t->flags = cast_byte(~0);
  t->array = NULL;
  t->sizearray = 0;
  setnodevector(L, t, 0);
  return t;


      vmcase(OP_NEWTABLE) {
        int b = GETARG_B(i);
        int c = GETARG_C(i);
        Table *t = luaH_new(L);
        sethvalue(L, ra, t);
        if (b != 0 || c != 0)
          luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
        checkGC(L, ra + 1);