lua-users home
lua-l archive

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


Hi guys,

New feature on the horizon: CONSTANT behavior in lua

It will work applying a LOCK on values stored in a table - any table.
It is planned to be a low level implementation in C code that requires
more ou less 8 target processor instructions overhead per assignment
(1 C if and 1 AND) when the target value is unlocked. Controlled by 3
functions:  lkset(value), lkreset(value), lkget(value)

EXAMPLES

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

a = {}
a.AConst = lkset(10)
...
a.AConst = lkset(20)  -- error
>>> error: attempt to change a locked value:  10

a.AConst = lkreset(a.AConst) -- unlocked
a.AConst = 20                -- ok

OPTIONAL FEATURE
_G.print = lkset(_G.print,true)  -- locks FOREVER - cannot be unlocked

BENEFITS
- Great to create constant behavior
- Great to avoid accidental or malicious function reassignment
- Very fast because executes a very short and fast native machine code.

Someone wants to help?

A good knowledge of table implementation in Lua will shorten the work.
A environment ready to make lots of benchmarks to measure the impact
on regular Lua code will help too.

-- 
Nilson