Personal tools
You are here: Home cmgui Wiki Using Cmiss Perl
Views
FrontPage >>

Using Cmiss Perl

last edited 2 months ago by cheng
  • Output. If you want all your commands echoed when they actually happen then you can get the interpreter (itp environment) to do this for you.
    'itp set echo on'
    By default the echoed commands are written verbatim. You can choose to add a string to the start of every echoed line using.....
    'itp set echo prompt :)'
  • Debug. If you really want to see the lexical analysis of the Perl interpreter then you can get the interpreter to write this out.
    'itp set debug on'
  • Comfiles.If you are reading a comfile containing a mixture of Perl and Cmiss commands then you must continue to read it in with read com;FILENAME or open comfile FILENAME exec so that the cmiss commands get mangled into Perl. If your script is pure perl then you can use require, do or use as normal.
  • Each space separated expression is assumed to be a single token for cmiss.
    i.e. gfx cre win "bob is a fish" creates a window called "bob is a fish" this means that
    $fred = "win bob"
    gfx cre $fred
    does not create a window called bob. To do something like this see the next section.
  • The cmiss command. The Perl interpreter works by declaring a function Perl_cmiss::cmiss or just cmiss, that is a valid Perl function. If for some reason the Perl interpreter won't interpret your cmiss command the way you think it should then you can pass this function a string and that string will go directly to cmiss.
    i.e. $bob = "win 10"; cmiss("gfx cre $bob");
  • The gfx * separator. As an asterisk now denotes multiplication the use of asterisks to separate directions in element and glyph sizes must now be quoted.
    gfx mod g_e heart element_points size 2*1*0.4 is actually the same as gfx mod g_e heart element_points size 0.8
    so instead quote the terms, gfx mod g_e heart element_points size "2*1*0.4"
  • Comments. The comment character is now a #.
  • open. As open is a valid function in Perl and a starting keyword in CMISS you currently need to escape the CMISS to use the Perl one. You could enclose it in ()'s or explicitly use its module name CORE::open.
  • Listing variables. You can list all your defined variables by looking at the hash of your package. The hash is called cmiss::.
    print map { "$_\n" } keys %cmiss::;
    A more user friendly command for this may be put directly into cmiss. There are some routines for simplifying this in the module CMISS::Utils found in CMISS_ROOT/perl_lib, in particular pscalar, parray and phash.
  • ENV environment. If you want to reference something in your environment then you can just use the automatic Perl Hash ENV. So to reference the environment variable HOST use $ENV{HOST}.
    i.e. print "Host from ENV is $ENV{HOST}\n";
  • itp assert blocks closed. The interpreter suspends execution of commands until all control structures are complete, i.e. until the closing bracket of all if, for and while statements is reached. Sometimes you may be trapped inside some control loop, nothing will execute and you are unsure how deep you are. You can either keep typing } brackets to try and escape any control statements you are in or you can use the interpreter command, 'itp assert blocks closed'. This command will generate an error if you are in any level of control structure at that time, it will also reset the interpreter, immediately terminating any control structures that may be started without executing them.
  • Command line arguments. Cmiss commands can be passed directly to the interpreter through command line arguments. These are executed first, before any startup comfiles or command line comfiles. This is useful for simple operations such as defining variables used by a comfile. Valid Perl can be separated by semicolons to form multiple statements.
    i.e. cm -exec '$FRED="fredstring"; $BOB="bobstring"'

Contributing to this site

Please add to the wiki any relevant information that you think might be useful to other users of this website. For example, you might like to contribute your experiences, questions and answers.

You are encouraged to contribute to this site regardless of your level of experience. Contributions are welcomed from new and regular visitors.

If you ask a question and receive an answer from a developer you should record it in the wiki. This information is extremely useful and can help other users overcome the same problem.

See how to add and edit pages for more information.