[words] add SYSEVAL to run underlying OS commands

This commit is contained in:
Gwenhael Le Moine 2023-02-09 16:44:45 +01:00
parent 4483bb5e13
commit b3b02165a4
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 27 additions and 1 deletions

View file

@ -41,7 +41,7 @@ class Rpl < Interpreter
end
def run!( input )
stack = super
stack = super( input )
persist_state if @live_persistence
@ -64,6 +64,7 @@ class Rpl < Interpreter
prepend RplLang::Words::Store
prepend RplLang::Words::String
prepend RplLang::Words::StringAndList
prepend RplLang::Words::System
prepend RplLang::Words::Test
prepend RplLang::Words::TimeAndDate
prepend RplLang::Words::Trig

View file

@ -18,4 +18,5 @@ require 'rpl/words/time-date'
require 'rpl/words/trig'
require 'rpl/words/logarithm'
require 'rpl/words/filesystem'
require 'rpl/words/system'
require 'rpl/words/list'

24
lib/rpl/words/system.rb Normal file
View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
module RplLang
module Words
module System
include Types
def populate_dictionary
super
category = 'System'
@dictionary.add_word!( ['syseval'],
category,
'( string -- output ) run string in OS shell and put output on stack',
proc do
args = stack_extract( [[RplString]] )
@stack << Types.new_object( RplString, "\"#{`#{args[0].value}`}\"" )
end )
end
end
end
end