annotate 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 |
|
rev |
line source |
samer@4
|
1 % repl - Read-eval-print loop.
|
samer@4
|
2 %
|
samer@4
|
3 % repl ::
|
samer@4
|
4 % string ~'command line prompt',
|
samer@4
|
5 % E:struct ~'structure fields to put in current environment',
|
samer@4
|
6 % -> {...}.
|
samer@4
|
7 %
|
samer@4
|
8 % Runs an embedded command interpreter much like the Matlab top-level.
|
samer@4
|
9 % The second argument E is available as a value with the name E in the environment.
|
samer@4
|
10 % The environment can be examined using WHO or WHOS as usual, but there will be
|
samer@4
|
11 % some other variables visible that are internal to repl - they all end with two
|
samer@4
|
12 % underscores so they can be easily recognised.
|
samer@4
|
13 % The repl can return any number of values, but the values must be placed
|
samer@4
|
14 % by calling the ret(...) function within the repl.
|
samer@4
|
15
|
samer@4
|
16 function varargout=repl(pr__,E)
|
samer@4
|
17 fprintf('\n\nEntering REPL. Type "return","exit", or "quit" to finish.\n');
|
samer@4
|
18 fprintf('The function ret(..) sets return values.\n\n');
|
samer@4
|
19 cont__=true;
|
samer@4
|
20 returns__={};
|
samer@4
|
21 while cont__,
|
samer@4
|
22 str__=input([pr__,'>> '],'s');
|
samer@4
|
23 if strcmp(str__,'quit') break; end
|
samer@4
|
24 if strcmp(str__,'exit') break; end
|
samer@4
|
25 if strcmp(str__,'return') break; end
|
samer@4
|
26 try, eval(str__)
|
samer@4
|
27 catch ex__
|
samer@4
|
28 fprintf('\n%s\n',getReport(ex__));
|
samer@4
|
29 end
|
samer@4
|
30 end
|
samer@4
|
31 varargout=returns__;
|
samer@4
|
32
|
samer@4
|
33 function ret(varargin), returns__=varargin; cont__=false; end
|
samer@4
|
34 end
|