lua-users home
lua-l archive

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


Hi again,

On Tue, Jun 23, 2020 at 07:44:29PM +0900, Robert Burke wrote:
> > so if I understand correctly I can make a _real_ read-only table
> > only with the readonlytable() function?
> No, you could do the same thing with the inline code if it was more
> like the code in your function:
> 
> x = setmetatable({}, {
>     __index    = x,
>     __newindex = function(x, key, value)
>                     error("Attempt to add a new or modify an exists
> item to a read-only table")
>                 end,
>     __metatable = false
> });

ah, thanks - it works as well.

Now I have to figure out how can I use it through C-API.

If you have any idea, please let me know :)

> > And in this case what happens with the "original" table?
> 
> It lives on because your table holds a reference to the metatable and
> the metatable holds a reference to the old table. But hopefully no
> other code can get a reference to it, because then it wouldn't really
> be read-only!

It's clear, I just want to understand how can I calculate with
memory usage. Imho it's a bit wastefull.


Thanks,


a.