lua-users home
lua-l archive

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


This is the best that can be done currently:
 https://github.com/Pogs/lua-snippets/blob/master/table-import.lua

It's handicapped in that it of course can't make locals.

Not sure if I’d call that the ‘best’, but it’s certainly one solution.

I’d probably prefer to use something like :

   function import(name)
       local mod = require(name)
       return function(t)
           for k,v in pairs(t) do
               t[k] = mod[v]
           end
           return unpack(t)
       end
   end

Import locals:

   local C,V = import "lpeg" { "C", "V" }

Import globals:

   C,V = import "lpeg" { "C", "V" }

Note this modifies the table passed in, but could just as easily return a new table.

- Claire.