Is there a base table from which all tables are created?

Suppose I wanted all tables ever created to understand some function that I’m about to write. Is there a master table that is copied to create new tables? What’s its name?
Thanks,
R

As far as I know, a table is just a section of memory waiting for you to put whatever you want into it. Theres only certain info you can put into Lua tables, so I guess you could create a master table for yourself that you can use to create future tables.

Take a look at meta-tables in the Lua guide.

thanks @yojimbo2000 i had forgotten about those. there must be some base because otherwise they’d not understand [] and such. maybe :slight_smile: i’ll read that area again. skimmed it last time …

hmm no, lua creates tables w/o metatables, it says here …

Suppose I wanted all tables ever created to understand some function

function myFunc(t) do something on t end
myFunc( any_table )

any table ever created understands myFunc…?

yes, and i suppose that’s why we have table.insert instead of any_table:insert, but I don’t like it much. Was thinking it’d be nice to have functional programming style methods on tables, like any_table:inject(0, function(sum,each) { return sum+each } but I guess I’ll have to do it another way. Maybe just build a Collection object …

@RonJeffries - I think the closest to what you want would be something like this

First create a class that accepts a table parameter in its initialisation.

Add class methods that mirror the usual table functions and add the extra ones you want.

Then the only change in syntax in your main program is when you create an instance

--instead of 
A = {1,2,3}
--you write
A = myTableClass{1,2,3}
--now use A exactly like a regular table, plus your special methods

Interesting thought, @Ignatz, and fun because it flies in the face of the general dictate not to do real work on the class side, so it might be fun to go that way.

That said, it may turn out that one needs the instance to do much and that the instance-side and : notation will be what one really wants. I’m suspecting that to be the case …