lua-users home
lua-l archive

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


On Tue, 28 Sep 2010 04:34:06 +0300, Nilson <nilson.brazil@gmail.com> wrote:

Hi guys,

New feature on the horizon: CONSTANT behavior in lua
...

What exactly are the semantics of the functions that you propose?
What is the intended use of such feature?

myprint = function(...) print('Hi',...) end
_G.print = lkset(_G.print)  -- protects against accidental change
_G.print = myprint
error: attempt to change a locked value:  function: 004755D8

so what exactly gets locked -- value of function 'print' or value
at the key 'print' in table _G?

i.e:

local a = lkset({}) -- is a locked?
local b = { k = a } -- is b.k locked?
local c, d = {}, {}
c.k = {}
d.k = c.k
c.k = lkset(c.k) -- is d.k locked now?
c.k.v = 1 -- does this work?
setmetatable(c.k, evil_metatable) -- does this work?