fityk icon indicating copy to clipboard operation
fityk copied to clipboard

Pass argument(s) to lua script via `exec`

Open Fellow-baka opened this issue 4 years ago • 2 comments

Is there a way to pass command-line-arguments to lua scripts from fityk command line? I would like to do something like this exec script.lua path\to\my\data or_maybe_some_parameter. I tried to put inside

local params = {...}
params[1] -- first parameter, if any.
params[2] -- second

or access it via global arg[0] table to no avail.

To add a bit of context here: I started to work with a large datasets on a regular basis and want to automatize part of handwork. Now my lua scripts contain next lines:

local path = "C:\\Users\\baka\\sobaka\\EXPERIMENTS\\smth\\S3_(ac)\\"
-- more code
file = io.open(path .. "center.dat", "w")
--more code

and I start the lua script from within a fityk GUI as exec C:\Users\baka\sobaka\EXPERIMENTS\smth\S3_(ac)\script.lua This approach is not the best one since I have to copy script to each folder and manually change path variable and call script with a full address.

The Idea was to put this script to default fityk folder (C:\Program Files (x86)\Fityk) and pass a path for output as a command line argument as exec script.lua C:\Users\baka\sobaka\EXPERIMENTS\smth\S3_(ac)\. Is there a way to do it?

Thanks in advance!

Fellow-baka avatar Aug 27 '19 19:08 Fellow-baka

You cannot pass an arguments, but any variables that you set in Fityk's Lua interpreter are preserved between commands. So you can do:

lua path="C:\\Users\\baka\\sobaka\\EXPERIMENTS\\smth\\S3_(ac)\\"
exec script.lua

and access path from script.lua. If you'd prefer to put it into a single line:

lua param1='something'; dofile('script.lua')

wojdyr avatar Aug 28 '19 09:08 wojdyr

That is beautiful! Thank you!

However there is another related problem: This approach works perfectly with freshly opened Fityk. But as soon as I open saved project I cannot call scripts from default (C:\Program Files (x86)\Fityk) path anymore without providing full path again. In both cases output of info set cwd is '' type: 'string ' Do you have any ideas why it behaves in such a way and if there is a way fix this?

Fellow-baka avatar Aug 28 '19 15:08 Fellow-baka