lua-users home
lua-l archive

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


On 31 May 2016 at 05:42, Justin Donaldson <jdonaldson@gmail.com> wrote:
> it needs to track its length in order to accommodate nil values


The usual approach to store nil values in a table is to use your own
'pseudo nil' value.

------
local mynil = {}

function set(t,k,v)
    if v == nil then v = mynil end
    t[k] = v
end

function get(t,k)
    local v = t[k]
    if v == mynil then v = nil end
    return v
end
-------



-- 
Javier