rpl.rb/lib/core/filesystem.rb

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