rpl.rb/lib/rpl/core/filesystem.rb
Gwenhael Le Moine 8b07724e50
make it a gem
2022-02-15 17:06:19 +01:00

40 lines
1.4 KiB
Ruby

# frozen_string_literal: true
module RplLang
module Core
module FileSystem
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( [%i[string]] )
path = File.absolute_path( args[0][:value] )
@stack << { type: :string,
value: File.read( path ) }
end )
@dictionary.add_word( ['feval'],
'Filesystem',
'( filename -- … ) read and run file',
proc do
run( 'fread eval' )
end )
@dictionary.add_word( ['fwrite'],
'Filesystem',
'( content filename -- ) write content into filename',
proc do
args = stack_extract( [%i[string], :any] )
File.write( File.absolute_path( args[0][:value] ),
args[1][:value] )
end )
end
end
end
end