rpl.rb/lib/rpl/words/filesystem.rb

42 lines
1.4 KiB
Ruby
Raw Normal View History

2022-02-10 14:50:59 +01:00
# frozen_string_literal: true
2021-12-15 13:33:52 +01:00
module RplLang
module Words
module FileSystem
2022-02-26 18:53:39 +01:00
include Types
def populate_dictionary
super
2021-12-15 13:33:52 +01:00
category = 'Filesystem'
@dictionary.add_word!( ['fread'],
category,
'( filename -- content ) read file and put content on stack as string',
proc do
args = stack_extract( [[RplString]] )
path = File.expand_path( args[0].value )
@stack << Types.new_object( RplString, "\"#{File.read( path )}\"" )
end )
@dictionary.add_word!( ['feval'],
category,
'( filename -- … ) read and run file',
Types.new_object( RplProgram, '« fread eval »' ) )
@dictionary.add_word!( ['fwrite'],
category,
'( content filename -- ) write content into filename',
proc do
args = stack_extract( [[RplString], :any] )
File.write( File.expand_path( args[0].value ),
args[1].value )
end )
end
2021-12-15 13:33:52 +01:00
end
end
end