author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年09月08日 11:08:11 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年09月08日 11:08:11 +0200 |
commit | 5649c4f2cd5f7c2f6a4342cbbce03bb01eb10f7b (patch) | |
tree | 0ce886c5cbed278cf914c9b3825a93323a12675b /agg-plot/lua-plot.cpp | |
parent | 4f616877375d742ac07c2935fa7e9ba854ac5701 (diff) | |
download | gsl-shell-5649c4f2cd5f7c2f6a4342cbbce03bb01eb10f7b.tar.gz |
-rw-r--r-- | agg-plot/lua-plot.cpp | 8 |
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 6b1d9254..674d2738 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -590,6 +590,14 @@ plot_save_svg (lua_State *L) if (!filename) return gs_type_error(L, 2, "string"); + unsigned fnlen = strlen(filename); + if (fnlen <= 4 || strcmp(filename + (fnlen - 4), ".svg") != 0) + { + const char* basename = (fnlen > 0 ? filename : "unnamed"); + lua_pushfstring(L, "%s.svg", basename); + filename = lua_tostring(L, -1); + } + FILE* f = fopen(filename, "w"); if (!f) return luaL_error(L, "cannot open filename: %s", filename); |