view general/repl.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents e44f49929e56
children
line wrap: on
line source
% repl - Read-eval-print loop.
%
% repl ::
%    string      ~'command line prompt',
%    E:struct  ~'structure fields to put in current environment',
% -> {...}.
%
% Runs an embedded command interpreter much like the Matlab top-level.
% The second argument E is available as a value with the name E in the environment.
% The environment can be examined using WHO or WHOS as usual, but there will be
% some other variables visible that are internal to repl - they all end with two
% underscores so they can be easily recognised.
% The repl can return any number of values, but the values must be placed
% by calling the ret(...) function within the repl.
 
function varargout=repl(pr__,E)
	fprintf('\n\nEntering REPL. Type "return","exit", or "quit" to finish.\n');
	fprintf('The function ret(..) sets return values.\n\n');
	cont__=true;
	returns__={};
	while cont__,
		str__=input([pr__,'>> '],'s');
		if strcmp(str__,'quit') break; end
		if strcmp(str__,'exit') break; end
		if strcmp(str__,'return') break; end
		try, eval(str__)
		catch ex__
			fprintf('\n%s\n',getReport(ex__));
		end
	end
	varargout=returns__;

	function ret(varargin), returns__=varargin; cont__=false; end
end