lua-users home
lua-l archive

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


On Mon, Sep 27, 2010 at 10:54 PM, Andre Leiradella <andre@leiradella.com> 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...
>

Andre,

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
behavior.

Besides that:

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
implementation.

-- 
Nilson