[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: CONSTANTS patch - LKBIT
- From: Andre Leiradella <andre@...>
- Date: Tue, 28 Sep 2010 00:01:48 -0300
On 27/09/2010 23:52, Nilson wrote:
Sorry if I'm missing something, but how can you do that without patching
the VM? AFAIK, the only way to make a table read-only in vanilla Lua is
On Mon, Sep 27, 2010 at 10:54 PM, Andre Leiradella<firstname.lastname@example.org> wrote:
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)
You can do that using metatables...
I know. Lua is great.
But a native C implementation of CONSTANTS would be at least 50 times
faster than a metatable implementation because:
1) Lua is interpreted.
2) The metatable implementation requires many VM operations and ***
some additional memory (what to protect) *** to implement the same
1) a library is a standard feature, so standardizes the implementation
of constants in team projects with no effort.
2) it is ready, so saves programmer's time to code and test.
3) It is ready, so people can create constants and protect functions more often
4) The library will be very small (I calculate less than 30 lines of C
code) and requires no extra memory per value protected.
5) Well, IMHO as constant feature is a very common concept in many
programming languages, it could deserve a standard library