Skip to content
Snippets Groups Projects
Commit 6ebc40df authored by Leif Andersson's avatar Leif Andersson
Browse files

Using include_string instead of include.

parent 0757000a
Branches restructuring
No related tags found
No related merge requests found
name = "ModJuliaTikz"
uuid = "03fd23bd-cacd-4584-a80b-c389ae8a36ca"
authors = ["Leif Andersson <leif.andersson@control.lth.se>"]
version = "0.1.0"
version = "0.2.0"
[compat]
julia = "1"
......
......@@ -44,9 +44,8 @@ function printcsv(data::Array{Any}, csv="")
end
end
"""
JuliaTikz(tikzfile,delete=true)
JuliaTikz(tikzfile,write_file=false)
Extract and run the Julia part of a combined tikz/Julia file.
......@@ -54,20 +53,12 @@ The boundary between the two is the string
\\endinput Julia <name>
where `<name>` is the name that will be given to the Julia file
(with .jl appended), and also to a variable `name` in the program,
i.e. name = "<name>".
The Julia file will be extracted to a temporary directory, which will be
deleted after the run unless the optional argument `delete` is false.
where `<name>` is the name that will be given to a variable `name`
in the program, and also to the Julia file (with .jl appended),
if the optional argument `write_file` is true.
"""
function JuliaTikz(tikzfile,delete=true)
dir = mktempdir();
filespec = ""; out="";
if !delete
println("Opening " * tikzfile)
end;
function JuliaTikz(tikzfile,write_file=false)
open(tikzfile) do file
res = nothing;
while res === nothing
......@@ -79,28 +70,26 @@ function JuliaTikz(tikzfile,delete=true)
end;
global name = res.captures[2];
filespec = join([dir, name * ".jl"],"/");
out = open(filespec,"w");
if !delete
println("Writing " * filespec);
end;
line = "module " * name;
println(out, line);
line = "import ..ModJuliaTikz: printcsv";
println(out, line);
global progLines = String[]
push!(progLines,"module " * name * "\n")
push!(progLines,"import ..ModJuliaTikz: printcsv\n")
while !eof(file)
println(out,readline(file));
end;
println(out,"end");
close(out);
push!(progLines,readline(file;keep=true))
end;
include(filespec);
end
push!(progLines,"end\n")
if delete
rm(dir,recursive=true);
else
return filespec;
end;
end;
if write_file
dir = mktempdir();
filespec = join([dir, name * ".jl"],"/");
println("Writing new" * filespec)
open(filespec,"w") do out
for i in eachindex(progLines)
print(out,progLines[i])
end
end
end
include_string(Main,join(progLines),name)
end # JuliaTikz
end; # end module
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment