rpl.rb/lib/rpl/core/filesystem.rb

41 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
2022-02-10 14:50:59 +01:00
module Core
module FileSystem
def populate_dictionary
super
2021-12-15 13:33:52 +01:00
@dictionary.add_word( ['fread'],
'Filesystem',
'( filename -- content ) read file and put content on stack as string',
proc do
args = stack_extract( [%i[string]] )
2021-12-15 16:36:11 +01:00
path = File.absolute_path( args[0][:value] )
2021-12-15 16:36:11 +01:00
@stack << { type: :string,
value: File.read( path ) }
end )
2022-02-11 16:15:01 +01:00
@dictionary.add_word( ['feval'],
'Filesystem',
'( filename -- … ) read and run file',
proc do
run( 'fread eval' )
end )
2022-02-11 16:15:01 +01:00
@dictionary.add_word( ['fwrite'],
'Filesystem',
'( content filename -- ) write content into filename',
proc do
args = stack_extract( [%i[string], :any] )
2021-12-15 16:36:11 +01:00
File.write( File.absolute_path( args[0][:value] ),
args[1][:value] )
end )
end
2021-12-15 13:33:52 +01:00
end
end
end