lua-users home
lua-l archive

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


Gang, can this following code be condensed somehow into a single execution
"block" (without making it a subroutine)?


    local table = GetSomeTable()
    if table then
       result = table[key]
    end


I currently have something like this:

   local result = GetSomeResult()

   if result == nil then
    local table = GetSomeTable()
    if table then
       result = table[key]
    end

   return result


And I'm wondering if there is a way to make it more "inline" like:

   return GetSomeResult() or
        do
            local table = GetSomeTable()
            if table then
                return table[key]
            end
            return nil
        end
     end