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

Allow for lua scripts in local .sc directory #259

Merged
merged 5 commits into from
May 31, 2018

Conversation

rjungemann
Copy link
Contributor

@rjungemann rjungemann commented May 22, 2018

# Make a new project directory
mkdir sc-im-test
cd sc-im-test

# Add the lua script
mkdir lua
echo 'function trg(c,r)' >> lua/test.lua
echo '  sc.lsetstr(1,1,"String From Lua")' >> lua/test.lua
echo '  sc.sc("LET A2=5")' >> lua/test.lua
echo 'end' >> lua/test.lua

# Add the spreadsheet
echo 'set external_functions' >> test.sc
echo 'trigger a5 "mode=W type=LUA file=test.lua function=trg"' >> test.sc
echo 'goto A1' >> test.sc

# Finally, open the spreadsheet with `../sc-im/src/sc-im test.sc` or similar,
# and modify cell A5 to make sure Lua is called.

Open path/to/sc-im test.sc and change cell A5. This will trigger the lua script to run.

In order to get Lua support working on OS X, the compiler flags needed to be changed slightly. -Wl,--export-dynamic is not supported, -rdynamic must be used instead.

@andmarti1424
Copy link
Owner

This seems great. Could you please update doc file as well? If @roman65536 agrees, I will merge this.

@rjungemann
Copy link
Contributor Author

Will do, thank you!

@roman65536
Copy link
Collaborator

roman65536 commented May 23, 2018

look good to me.
@Roger let me know, if it all works correctly.

Ehh.. would you mind post the content of test2.lua as well ? For more details, take a look in example/lua, there are 2 example on trigger, stock.sc and getstock.lua on READ , which auto download from yahoo finance the stock prices and the other one trg_sql3.lua on WRITE, which inserts same values in to sqlite db. Both are examples.

As you can see there, the function should be defined as :
function trg(c, r )
..
..
end

where c,r is column and row of the triggered cell.

rgds
Roman

@andmarti1424
Copy link
Owner

And please @rjungemann, can you update the "doc" file as well?

@rjungemann
Copy link
Contributor Author

rjungemann commented May 23, 2018

Yep, after work I'll update the docs.

I renamed test2.lua to test.lua but didn't update my comment. I'll fix test.lua so it calls a function. But yes, I can see running dtruss (closest thing to strace in OS X) that it found the Lua file properly and I could see by changing the cell that the Lua script was evaluated.

@rjungemann
Copy link
Contributor Author

rjungemann commented May 24, 2018

@andmarti1424 @roman65536 this should be ready to go now. Docs and description have been updated. I'll look into modifying C external functions so they work in the same way in a separate PR.

Sorry for the delay. Work got busy.

@andmarti1424
Copy link
Owner

Thanks @rjungemann!

@andmarti1424 andmarti1424 merged commit dd16460 into andmarti1424:freeze May 31, 2018
@andmarti1424
Copy link
Owner

Merged!

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

Successfully merging this pull request may close these issues.

None yet

3 participants