lua-users home
lua-l archive

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


On 04/09/2014 01:17 PM, steve donovan wrote:
On Wed, Apr 9, 2014 at 1:01 PM, Thomas Jericke <tjericke@indel.ch> wrote:
local a,b,c in assert_index, require "mylib"
local x, y, z in _ENV
local sockets, mysql, json in require -- loads several libraries as local
tables
That is indeed very expressive and I see how it's useful to have a
function after in. (although I don't understand the intent of the
first statement)

function assert_index (table, key)
    local tmp = table[key]
assert(tmp ~= nil, "assertion failed: assert_index expected table to provide field: " .. key)
    return tmp
end

local a,b,c in assert_index, require "mylib"

gets a, b, c from module "mylib" and asserts that they are not nil.

--
Thomas