lua-users home
lua-l archive

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

I'm trying to put together a non-empty false value, and I can't figure
out a way to do it. It seems to me that in order to do this I would
need a tag method which is used for boolean comparison (as opposed to
assignment). That way I could do:

FALSE = {}
local a_tag = newtag();

    function (a_table) 
       return nil;               

Do any of you know an existing method for getting this kind of behavior?


I have three reasons for wanting to do this:

1) My first motivation for this is that in proto-style "parent"
inheritence schemes, any values which are "nil" are not-present, which
means that accessing them requires a search of the entire inheritence
tree, just to not find the nil value. 

2) My second motivation is that Lua "nil" false values confuse the nice
proto-override style inheritence behavior. That is, if I have:

  super_obj = {
     foo_integer = 1
     bar_boolean = 1

  child_obj = {
     parent = super_obj

Then the following works great:

 print(child_obj.foo_integer) -- 1
 child_obj.foo_integer = 2
 print(child_obj.foo_integer) -- 2
 child_obj.foo_integer = nil
 print(child_obj.foo_integer) -- 1

However, booleans are confused:

 print(child_obj.bar_boolean) -- 1
 child_obj.bar_boolean = nil       -- i.e. false
 print(child_obj.bar_boolean) -- 1

In other words, there is no way to set a "false" value for the

3) And finally, my third motivation. I'm trying to come up with a
scheme to 'cache' a parent inheritence heirarchy. I want to do this
because multi-level and multi-parent heirarchies take a long time to
search, so instead I'd like to flatten a given heirarchy, and only
reparse it when it changes. However, this only works well if the
heirarchy is changed infrequently, and any boolean value stored in the
heirarchy makes items appear and disappear frequently, causing
thrashing of the cache.

David Jeske (N9LCA) + +