class Dyndoc::JLServer

Public Class Methods

echo(code,prompt="julia> ",tab=2) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 882
    def JLServer.echo(code,prompt="julia> ",tab=2)
            out=""
            res=JLServer.inputsAndOutputs(code)
            ##
            Dyndoc.warn "JLServer",res
return "Error when executing: "+code unless 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" unless cmd[:input].strip[-1]==";"
                    ## Dyndoc.warn "output1",out
  if cmd[:error]==""
                    out << ((cmd[:output]=="nothing" or (cmd[:input].strip)[-1]==";")  ? "" : cmd[:output])
    out << ((cmd[:output2]=="nothing" or (cmd[:input].strip)[-1]==";")  ? "" : cmd[:output2]) #cmd[:output2]
            else
                      out << cmd[:error]
  end
                    out << (cmd[:output]=="nothing" ? "" : "\n")
                    ## Dyndoc.warn "output3",out
            end
            out
    end
echo_verb(txt,mode) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 905
    def JLServer.echo_verb(txt,mode)
  txtout=Dyndoc::JLServer.echo(txt).strip
      ## p [:jl_echo_verb,txtout]
  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
  ## p [:out, out]
      out
end
eval(code) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 849
def JLServer.eval(code)
        Julia.eval("capture_output_julia("+code.strip.inspect.gsub("$","\\$")+")")
end
initVerb() click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 832
def JLServer.initVerb
        Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
        Julia << "push!(Libdl.DL_LOAD_PATH,\"/usr/lib\");push!(Libdl.DL_LOAD_PATH,\"/usr/local/lib\")"
        @@initVerb=true
end
inputsAndOutputs(code,hash=true) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 838
    def JLServer.inputsAndOutputs(code,hash=true)
            JLServer.initVerb unless @@initVerb
Dyndoc.logger.info("JLServer.inputsAndOutputs: "+code.strip)
    res=(Julia << 'capture_output_julia('+code.strip.inspect.gsub("$","\\$")+')')
Dyndoc.logger.info("JLServer.inputsAndOutputs:"+res.inspect)
res.map!{|input,output,output2,error,error2|
                    {:input=>input,:output=>output,:output2=>output2,:error=>error,:error2=>error2}
            } if res and hash
            res
    end
output(code,opts={}) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 853
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
        
        res=JLServer.inputsAndOutputs(code,false)
        Dyndoc.warn "jlserv.output",[code,res]
        return "" unless res
        res=res.map{|input,output,output2,error,error2|
                #Dyndoc.warn "output",output
                output
        }
        res.length==0 ? "" : res[-1] 
end
outputs(code,opts={}) click to toggle source
# File lib/dyndoc/base/filter/server.rb, line 868
def JLServer.outputs(code,opts={}) #may have more than one lines in code
        ## Dyndoc.warn "JLServer.outputs opts",opts
        ##
        Dyndoc.warn "JLServer code",code
        res=JLServer.inputsAndOutputs(code,false)
        if opts[:block]
                return "" unless res
                res.map{|input,output,output2,error,error2|
                        ## Dyndoc.warn "output2",output2
                        output
                }.join("\n")
        end
end