[words] add SYSEVAL to run underlying OS commands
This commit is contained in:
parent
4483bb5e13
commit
b3b02165a4
3 changed files with 27 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
24
lib/rpl/words/system.rb
Normal 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
|
Loading…
Reference in a new issue