sc-im
sc-im copied to clipboard
Allow for local external scripts
Hey there, I noticed I can't run external scripts in the same directory as my .sc files (trying the examples in the examples/ directory). I know I can put them in /usr/local/share/scim/lua but it would be nice to have project-specific scripts too. (I tried a few things like prefixing with ./ or hard-coding absolute paths but I couldn't get it to work)
I tried digging in myself and I'll see if I can figure it out myself. But it would be helpful for me to have project-specific scripts.
Thank you! I'll continue donating to this project when I can because it is very helpful for me!
What kind of scripts are you refering to?
sc scripts? how your are loading or calling them?
Sorry, I didn't describe it well. I imagined if I have a .sc file with trigger a5 "mode=W type=LUA file=./trg_sql3.lua function=trg" (a ./ in front of the script name), it would look for trg_sql3.lua in current directory instead of /usr/local/share/scim/lua. This might already work and I might be doing something wrong.
I did add set external_functions above my trigger call. I'll post what I'm trying to do shortly.
It might be looking it first in $HOME/.scim/lua/.. If not found, then it might look in the HELP_PATH defined in Makefile..
I'll see if I can come up with a PR what I had in mind... from the docs:
The search path for LUA trigger files is
$HOME/.scim/lua/ or /usr/local/share/scim/lua
(in that order) and for C Trigger
$HOME/.scim/module or /usr/local/share/scim/module
What I envisioned might be something like:
The search path for LUA trigger files is
$PWD/.scim/lua, $HOME/.scim/lua/, or /usr/local/share/scim/lua
(in that order) and for C Trigger
$PWD/.scim/module, $HOME/.scim/module, or /usr/local/share/scim/module
Did scim find your file then?
Unfortunately, no. This is what I'm testing with:
In a directory called sc-im-test I have 2 files:
test2.sc:
set external_functions
let A1 = 1
let A0 = @ston (@ext ("echo", a1))
trigger a5 "mode=W type=LUA file=test2.lua function=trg"
test2.lua:
sc.lsetstr(1,1,"test")
In the above example, let A0 = @ston (@ext ("echo", a1)) works when loading the file, but the trigger call does not. I tried a few different paths for it. (test2.lua, ./test2.lua, and /Users/RogerJungemann/Desktop/sc-im-test/test2.lua do not work)
rjungemann,
The Lua trigger should be in "lua/" directory. In your example above, test2.lua is searched in "lua/" directory (see lua.c). Either in $HOME/.scim/lua or $HELP_PATH/lua
The best way to find it, is by strace the sc-im (strace -f -o /tmp/test.out sc-im and grep for test2.lua). Btw if you define "trg" as the calling function, you have to write that function as in trigger.lua described (since cell infos are passed to the function). see lua.c -> doLuaTrigger_cell() for details how the lua is called.
BTW: depending on what you do, don't be supprised when you write to a cell and it wont get the result you like. In your example above, you define a "write" trigger on a5. When hitting it (by writing/modifying a5), you write to a1 "test". However a1 may be overwrite, since there is already a1=1 defined. If you do something like this, the cell you write to sould be empty resp. no evaluation should be defined. Otherwise, cell will be overwriten when eval() or seval() is called.
rgds Roman
Thanks @roman65536 !
@roman65536 this means that all my scripts need to be put in a central location and can't be put in a directory with the .sc file, which makes it hard to share spreadsheets with people. That's what I'm trying to get at. The script works if it's placed in $HOME/.scim/lua or $HELP_PATH/lua, but this is less useful.
My question was not a general "why does my script not work" question. My question was, "is it possible to have my .sc file and my lua scripts in the same place, so I can more easily share them between computers, etc."
In my opinion, it would be useful to check for lua scripts in $PWD/lua as well as $HOME/.scim/lua and $HELP_PATH/lua. That way I can have a directory with my .sc file in it, which contains a ./lua directory with my scripts.
I have a PR that I'll post shortly with what I'm proposing
@rjungemann I think, I know where you heading. I would suggest, extending file.c even more, extending it with .. lets say $SC_SEARCH environment variable. This way you can point $SC_SEARCH to a (example) nfs share and have all scripts in one place. Just as a thought.
roman
I'll look into it this weekend!