File: print.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (107 lines) | stat: -rw-r--r-- 2,840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
   FALCON - The Falcon Programming Language.
   FILE: print.cpp

   Basic module
   -------------------------------------------------------------------
   Author: $AUTHOR
   Begin: $DATE

   -------------------------------------------------------------------
   (C) Copyright 2004: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

/*#
   @beginmodule core
*/

#include <falcon/setup.h>
#include <falcon/module.h>
#include <falcon/item.h>
#include <falcon/vm.h>
#include <falcon/stream.h>

namespace Falcon {
namespace core {

/*#
   @function print
   @inset core_basic_io
   @param ... An arbitrary list of parameters.
   @brief Prints the contents of various items to the standard output stream.

   This function is the default way for a script to say something to the outer
   world. Scripts can expect print to do a consistent thing with respect to the
   environment they work in; stand alone scripts will have the printed data
   to be represented on the VM output stream. The stream can be overloaded to
   provide application supported output; by default it just passes any write to
   the process output stream.

   The items passed to print are just printed one after another, with no separation.
   After print return, the standard output stream is flushed and the cursor (if present)
   is moved past the last character printed. The function @a printl must be used,
   or a newline character must be explicitly placed among the output items.

   The print function has no support for pretty print (i.e. numeric formatting, space
   padding and so on). Also, it does NOT automatically call the toString() method of objects.

   @see printl
*/
FALCON_FUNC  print ( ::Falcon::VMachine *vm )
{
   Stream *stream = vm->stdOut();
   if ( stream == 0 )
   {
      return;
   }

   for (int i = 0; i < vm->paramCount(); i ++ )
   {

      Item *elem = vm->param(i);
      String temp;

      switch( elem->type() ) {
         case FLC_ITEM_STRING:
            stream->writeString( *elem->asString() );
         break;

         default:
            elem->toString( temp );
            stream->writeString( temp );
      }
   }

   stream->flush();
}

/*#
   @function printl
   @inset core_basic_io
   @param ... An arbitrary list of parameters.
   @brief Prints the contents of various items to the VM standard output stream, and adds a newline.

   This functions works exactly as @a print, but it adds a textual "new line" after all the
   items are printed. The actual character sequence may vary depending on the underlying system.

   @see print
*/
FALCON_FUNC  printl ( ::Falcon::VMachine *vm )
{
   Stream *stream = vm->stdOut();
   if ( stream == 0 )
   {
      return;
   }

   print( vm );
   stream->writeString( "\n" );
   stream->flush();
}


}}

/* end of print.cpp */