Commodity = {
	_VERSION = "1.0";
}

setmetatable(_ENV, {
	__index = function(s,k)
		local p = load(k);
		if p then
			local f = function(z)
				local s = trainName;
				trainName = z;
				p();
				trainName = s;
			end;
			_ENV[k] = f;
			return f;
		end;
		return nil;
	end
});

function assertParam(paramNr, nilAllowed, typeAllowed, ...)
	local name, value = debug.getlocal(2, paramNr);
	local message;
	if name == nil then
		message = "Parameter " .. tostring(paramNr) .. " not found.";
	elseif value == nil then
		if nilAllowed then
			return true;
		end;
		message = "Parameter " .. name .. " must not be nil.";
	else
		local curType = type(value);
		local types = { typeAllowed, ... };
		for _, t in ipairs(types) do
			if t == curType then
				return true;
			end;
		end;
		message = "Parameter " .. name .. " is a " .. curType;
		if #types == 1 then
			message = message .. ", not a " .. typeAllowed .. ".";
		else
			local list;
			for i, t in ipairs(types) do
				if list then
					list = list .. " nor a " .. t;
				else
					list = t;
				end;
			end;
			message = message .. ", neither a " .. list .. ".";
		end;
	end;
	error(message, 2);
	return false;
end;

print("Commodity Version " .. Commodity._VERSION);

return Commodity;
