Module: RplLang::Words::FileSystem

Includes:
Types
Included in:
Rpl
Defined in:
lib/rpl/words/filesystem.rb

Instance Method Summary collapse

Methods included from Types

new_object

Instance Method Details

#populate_dictionaryObject



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
# File 'lib/rpl/words/filesystem.rb', line 8

def populate_dictionary
  super

  @dictionary.add_word( ['fread'],
                        'Filesystem',
                        '( filename -- content ) read file and put content on stack as string',
                        proc do
                          args = stack_extract( [[RplString]] )

                          path = File.absolute_path( args[0].value )

                          @stack << Types.new_object( RplString, "\"#{File.read( path )}\"" )
                        end )

  @dictionary.add_word( ['feval'],
                        'Filesystem',
                        '( filename -- … ) read and run file',
                        Types.new_object( RplProgram, '« fread eval »' ) )

  @dictionary.add_word( ['fwrite'],
                        'Filesystem',
                        '( content filename -- ) write content into filename',
                        proc do
                          args = stack_extract( [[RplString], :any] )

                          File.write( File.absolute_path( args[0].value ),
                                      args[1].value )
                        end )
end