Skip to content

Instantly share code, notes, and snippets.

@gvx
Created July 20, 2011 13:20
Show Gist options
  • Save gvx/1094934 to your computer and use it in GitHub Desktop.
Save gvx/1094934 to your computer and use it in GitHub Desktop.
Pythonesk "from ... import" in Lua, copying parts of a library into the global table
-- CC0, see http://creativecommons.org/publicdomain/zero/1.0/ etcetera, etcetera
function from(source, which)
local t = require(source)
local function import (which)
if which == '*' then
for k, v in pairs(t) do
if _G[k] == nil then
_G[k] = v
end
end
else
for i, v in ipairs(which) do
_G[v] = t[v]
end
end
end
if which then
return import(which)
else
return import
end
end
--[[ usage:
from 'lib' '*'
from 'lib2' {'ball', 'rectangle', 'close'}
from ('lib3', '*')
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment