Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass argument(s) to lua script via exec #29

Open
Fellow-baka opened this issue Aug 27, 2019 · 2 comments
Open

Pass argument(s) to lua script via exec #29

Fellow-baka opened this issue Aug 27, 2019 · 2 comments

Comments

@Fellow-baka
Copy link

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!

@wojdyr
Copy link
Owner

wojdyr commented Aug 28, 2019

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')

@Fellow-baka
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants