Class: Dyndoc::JLServer

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndoc/base/filter/server.rb

Constant Summary collapse

@@initVerb =

require ‘jl4rb’ Julia.init end

nil

Class Method Summary collapse

Class Method Details

.echo(code, prompt = "julia> ", tab = 2) ⇒ Object



850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/dyndoc/base/filter/server.rb', line 850

def JLServer.echo(code,prompt="julia> ",tab=2)
  out=""
  res=JLServer.inputsAndOutputs(code)
  ## Dyndoc.warn "JLServer",res
  res.each do |cmd|
    ## Dyndoc.warn "input",cmd
     out << prompt+ cmd[:input].split("\n").each_with_index.map{|e,i| i==0 ? e : " "*(prompt.length)+e}.join("\n").gsub(/\t/," "*tab)
    out << "\n"
    ## Dyndoc.warn "output1",out
    out << cmd[:output2]
    out << (cmd[:output]=="nothing"  ? "" : cmd[:output])
    ## Dyndoc.warn "output2",out
    out << cmd[:error]!=""  ? cmd[:error] : ""
    out << (cmd[:output]=="nothing"  ? "" : "\n\n")
    ## Dyndoc.warn "output3",out
  end
  out
end

.echo_verb(txt, mode) ⇒ Object



869
870
871
872
873
874
875
876
877
878
# File 'lib/dyndoc/base/filter/server.rb', line 869

def JLServer.echo_verb(txt,mode)
  txtout=Dyndoc::JLServer.echo(txt).strip
  mode=:default unless Dyndoc::VERB.keys.include? mode
  header= (mode!=:default) and txtout.length>0
  out=""
  out << Dyndoc::VERB[mode][:begin] << "\n" if header
  out << txtout
  out << "\n" << Dyndoc::VERB[mode][:end] << "\n" if header
  out
end

.eval(code) ⇒ Object



825
826
827
# File 'lib/dyndoc/base/filter/server.rb', line 825

def JLServer.eval(code)
  Julia.eval(code)
end

.initVerbObject



810
811
812
813
# File 'lib/dyndoc/base/filter/server.rb', line 810

def JLServer.initVerb
  Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
  @@initVerb=true
end

.inputsAndOutputs(code, hash = true) ⇒ Object



815
816
817
818
819
820
821
822
823
# File 'lib/dyndoc/base/filter/server.rb', line 815

def JLServer.inputsAndOutputs(code,hash=true)
  JLServer.initVerb unless @@initVerb
  res=(Julia << 'capture_julia('+code.strip.inspect+')')
  ## Dyndoc.warn "JLServer.inputsAndOutputs",res
  res.map!{|input,output,output2,error,error2|
    {:input=>input,:output=>output,:output2=>output2,:error=>error,:error2=>error2}
  } if hash
  res
end

.output(code, opts = {}) ⇒ Object



829
830
831
832
833
# File 'lib/dyndoc/base/filter/server.rb', line 829

def JLServer.output(code,opts={})
  opts={:print=>true}.merge(opts)
  ## Dyndoc.warn "jlserv",code+"|"+Julia.eval(code,:print=>opts[:print]).to_s
  Julia.eval(code,:print=>opts[:print]).to_s
end

.outputs(code, opts = {}) ⇒ Object

may have more than one lines in code



835
836
837
838
839
840
841
842
843
844
845
846
847
848
# File 'lib/dyndoc/base/filter/server.rb', line 835

def JLServer.outputs(code,opts={}) #may have more than one lines in code
  ## Dyndoc.warn "JLServer.outputs opts",opts
  ## Dyndoc.warn "JLServer code",code
  if opts[:block]
    res=JLServer.inputsAndOutputs(code,false)
    return "" unless res
    res.map{|input,output,output2,error,error2|
      ## Dyndoc.warn "output2",output2
      output2
    }.join("\n")
  else
    JLServer.eval(code)
  end
end