util/envload.lua
author Matthew Wild <mwild1@gmail.com>
Sat, 27 Apr 2013 14:59:00 +0100
changeset 5527 7e7f45f587a1
parent 5020 ef1eb65acbba
child 7731 da54ad64f6da
permissions -rw-r--r--
moduleapi: Add module:get_option_inherited_set() to return a set that inherits items from a globally set set, if set

-- Prosody IM
-- Copyright (C) 2008-2011 Florian Zeitz
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--

local load, loadstring, loadfile, setfenv = load, loadstring, loadfile, setfenv;
local envload;
local envloadfile;

if setfenv then
	function envload(code, source, env)
		local f, err = loadstring(code, source);
		if f and env then setfenv(f, env); end
		return f, err;
	end

	function envloadfile(file, env)
		local f, err = loadfile(file);
		if f and env then setfenv(f, env); end
		return f, err;
	end
else
	function envload(code, source, env)
		return load(code, source, nil, env);
	end

	function envloadfile(file, env)
		return loadfile(file, nil, env);
	end
end

return { envload = envload, envloadfile = envloadfile };