Discussion:
[darktable-user] dt lua script : Basic usage, please?
J Albrecht
2017-01-09 17:16:20 UTC
Permalink
Hello all,

Every so often I come across a post referencing “extra” lua scripts. They look to be quite intriguing. So much so that I’ve loaded them all from github into my .config/darktable directory and modified my luarc file with ‘require “script”’ etc. Alas, after doing this the expected additional functionality doesn’t seem to be available! Notwithstanding me being unable to get even a mere whiff of response from these github scripts, I can’t even get the simple example in the dt manual to work. For example:

9.1.2. A simple lua example
Let's start with a simple example. We will print some code on the console. Create a file called luarc in darktable's configuration directory (usually ~/.config/darktable/) and add the following line to it:

print("Hello World !")

Start darktable and you will see the sencence Hello World ! printed on the console.

Umm, no, nothing happened :-(

Can somebody please shed light on how some of us code-witless souls can “easily" make use of the lua script functionality? With all due respect, the current documentation is lacking effectiveness in this regard.

Many thanks in advance!
William Ferguson
2017-01-09 19:05:37 UTC
Permalink
Unfortunately the lua scripts aren't readily accessible to users without
some coding background :(. I'm currently working to address this with a
script manager that can be dropped in as the luarc file and provides a gui
element to download, update, enable and disable scripts. Right now it is
in testing, but hopefully it will be done soon.

In the meantime....

Lua looks for scripts using a set of paths. Therefore, if you specify a
script in the luarc such as

require "contrib/gimp"

then the lua interpreter looks for
~/.config/darktable/lua/contrib/gimp.lua.

So, in order to set this up you could do:

cd ~/.config/darktable
git clone https://github.com/darktable-org/lua-scripts.git lua


then you could edit your ~/.config/darktable/luarc to say (for instance):

-- include hugin
require "contrib/hugin"

-- and selection to pdf
require "official/selection_to_pdf"

-- and hello world
require "examples/hello_world"

Start up darktable and you should have scripts. If you have a problem,
then start darktable from the command line with darktable -d lua and lua
debugging messages will print in the console. The debugging messages start
with LUA ERROR, but they aren't necessarily errors.

Hope this helps,

Bill
Post by J Albrecht
Hello all,
Every so often I come across a post referencing “extra” lua scripts. They
look to be quite intriguing. So much so that I’ve loaded them all from
github into my .config/darktable directory and modified my luarc file with
‘require “script”’ etc. Alas, after doing this the expected additional
functionality doesn’t seem to be available! Notwithstanding me being unable
to get even a mere whiff of response from these github scripts, I can’t
9.1.2. A simple lua example
Let's start with a simple example. We will print some code on the console.
Create a file called *luarc* in darktable's configuration directory
print("Hello World !")
Start darktable and you will see the sencence *Hello World !* printed on
the console.
Umm, *no*, nothing happened :-(
Can somebody please shed light on how some of us code-witless souls can
“easily" make use of the lua script functionality? With all due respect,
the current documentation is lacking effectiveness in this regard.
Many thanks in advance!
J Albrecht
2017-01-09 19:22:04 UTC
Permalink
Thank-you very much, Bill, for your comments, understanding and refreshing lack of disdain for those of us who struggle to do much more than hit the hot spots in a gui! I’m going to follow your generous advice now to see if I can get some joy

Unfortunately the lua scripts aren't readily accessible to users without some coding background :(. I'm currently working to address this with a script manager that can be dropped in as the luarc file and provides a gui element to download, update, enable and disable scripts. Right now it is in testing, but hopefully it will be done soon.
In the meantime....
Lua looks for scripts using a set of paths. Therefore, if you specify a script in the luarc such as
require "contrib/gimp"
then the lua interpreter looks for ~/.config/darktable/lua/contrib/gimp.lua.
cd ~/.config/darktable
git clone https://github.com/darktable-org/lua-scripts.git <https://github.com/darktable-org/lua-scripts.git> lua
-- include hugin
require "contrib/hugin"
-- and selection to pdf
require "official/selection_to_pdf"
-- and hello world
require "examples/hello_world"
Start up darktable and you should have scripts. If you have a problem, then start darktable from the command line with darktable -d lua and lua debugging messages will print in the console. The debugging messages start with LUA ERROR, but they aren't necessarily errors.
Hope this helps,
Bill
Hello all,
9.1.2. A simple lua example
print("Hello World !")
Start darktable and you will see the sencence Hello World ! printed on the console.
Umm, no, nothing happened :-(
Can somebody please shed light on how some of us code-witless souls can “easily" make use of the lua script functionality? With all due respect, the current documentation is lacking effectiveness in this regard.
Many thanks in advance!
Tobias Ellinghaus
2017-01-09 22:10:04 UTC
Permalink
Post by J Albrecht
Hello all,
Hi.

[...]
Post by J Albrecht
I can’t
9.1.2. A simple lua example
Let's start with a simple example. We will print some code on the console.
Create a file called luarc in darktable's configuration directory (usually
print("Hello World !")
Start darktable and you will see the sencence Hello World ! printed on the console.
Umm, no, nothing happened :-(
Can somebody please shed light on how some of us code-witless souls can
“easily" make use of the lua script functionality? With all due respect,
the current documentation is lacking effectiveness in this regard.
That seems to indicate a general lack of Lua support in your installed
darktable. Please tell us what version of darktable you are using and how you
installed it. Until that minimalistic example isn't working it doesn't make
sense to try running the more useful scripts.
Post by J Albrecht
Many thanks in advance!
Tobias
J Albrecht
2017-01-09 23:01:07 UTC
Permalink
I’m running dt 2.2.1+3 g4596f0b5d on a Macbook Pro from the current dmg (https://github.com/darktable-org/darktable/releases/download/release-2.2.1/darktable-2.2.1.3.dmg).

Having followed Bills instructions, I subsequently faced the dreaded Spinning Beach Ball of Death upon opening dt. So clearly, something is awry

Post by Tobias Ellinghaus
Post by J Albrecht
Hello all,
Hi.
[...]
Post by J Albrecht
I can’t
9.1.2. A simple lua example
Let's start with a simple example. We will print some code on the console.
Create a file called luarc in darktable's configuration directory (usually
print("Hello World !")
Start darktable and you will see the sencence Hello World ! printed on the console.
Umm, no, nothing happened :-(
Can somebody please shed light on how some of us code-witless souls can
“easily" make use of the lua script functionality? With all due respect,
the current documentation is lacking effectiveness in this regard.
That seems to indicate a general lack of Lua support in your installed
darktable. Please tell us what version of darktable you are using and how you
installed it. Until that minimalistic example isn't working it doesn't make
sense to try running the more useful scripts.
Post by J Albrecht
Many thanks in advance!
Tobias
Tobias Ellinghaus
2017-01-10 08:56:28 UTC
Permalink
Post by J Albrecht
I’m running dt 2.2.1+3 g4596f0b5d on a Macbook Pro from the current dmg
(https://github.com/darktable-org/darktable/releases/download/release-2.2.1
/darktable-2.2.1.3.dmg).
Having followed Bills instructions, I subsequently faced the dreaded
Spinning Beach Ball of Death upon opening dt. So clearly, something is
awry

I don't know what features the OSX build has enabled. You could try removing/
renaming ~/.config/darktable/ (that is a hidden folder in your home directory)
and then running "darktable --version" from a terminal. That should show you
if Lua is supported.

Tobias

[...]
David Vincent-Jones
2017-01-10 16:47:06 UTC
Permalink
Tobias; following these instructions I see that lua is supported on my
system BUT the previous instructions for getting things going did not
bring any results. It all appears to be a bit complicated.

David
Post by Tobias Ellinghaus
Post by J Albrecht
I’m running dt 2.2.1+3 g4596f0b5d on a Macbook Pro from the current dmg
(https://github.com/darktable-org/darktable/releases/download/release-2.2.1
/darktable-2.2.1.3.dmg).
Having followed Bills instructions, I subsequently faced the dreaded
Spinning Beach Ball of Death upon opening dt. So clearly, something is
awry

I don't know what features the OSX build has enabled. You could try removing/
renaming ~/.config/darktable/ (that is a hidden folder in your home directory)
and then running "darktable --version" from a terminal. That should show you
if Lua is supported.
Tobias
[...]
J Albrecht
2017-01-10 19:03:07 UTC
Permalink
Post by Tobias Ellinghaus
I don't know what features the OSX build has enabled.
Tobias
Lua seems to be enabled



this is darktable 2.2.1+3~g4596f0b5d
copyright (c) 2009-2016 johannes hanika
darktable-***@lists.darktable.org

compile options:
bit depth is 64 bit
normal build
SSE2 optimized codepath enabled
OpenMP support enabled
OpenCL support enabled
Lua support enabled, API version 4.0.0
Colord support disabled
gPhoto2 support enabled
GraphicsMagick support enabled
OpenEXR support enabled
Tobias Ellinghaus
2017-01-10 21:14:09 UTC
Permalink
Post by J Albrecht
Post by Tobias Ellinghaus
I don't know what features the OSX build has enabled.
Tobias
Lua seems to be enabled

this is darktable 2.2.1+3~g4596f0b5d
copyright (c) 2009-2016 johannes hanika
bit depth is 64 bit
normal build
SSE2 optimized codepath enabled
OpenMP support enabled
OpenCL support enabled
Lua support enabled, API version 4.0.0
Colord support disabled
gPhoto2 support enabled
GraphicsMagick support enabled
OpenEXR support enabled
That looks fine. Please try running darktable like this from a terminal:

darktable --luacmd 'print("Lua seems to work")'

Does it print "Lua seems to work"?
J Albrecht
2017-01-10 22:00:22 UTC
Permalink
Post by Tobias Ellinghaus
darktable --luacmd 'print("Lua seems to work")'
Indeed, albeit after some worrisome gtk warnings, the line was printed


(process:24912): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.
2017-01-10 16:57:31.944 darktable-bin[24912:440876] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.

(darktable-bin:24912): GLib-GObject-WARNING **: invalid cast from 'GtkMenuBar' to 'GtkWindow'

(darktable-bin:24912): Gtk-CRITICAL **: gtk_window_add_accel_group: assertion 'GTK_IS_WINDOW (window)' failed

(darktable-bin:24912): Gdk-WARNING **: GdkQuartzDisplay does not implement the monitor vfuncs
Lua seems to work
David Vincent-Jones
2017-01-10 22:03:56 UTC
Permalink
It worked just fine on my system

David
Post by J Albrecht
Post by Tobias Ellinghaus
darktable --luacmd 'print("Lua seems to work")'
Indeed, albeit after some worrisome gtk warnings, the line was printed

(process:24912): Gtk-*WARNING***: Locale not supported by C library.
Using the fallback 'C' locale.
Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and
later. It should not be used in new applications. Use
convertRectToBacking: instead.
(darktable-bin:24912): GLib-GObject-*WARNING***: invalid cast from
'GtkMenuBar' to 'GtkWindow'
assertion 'GTK_IS_WINDOW (window)' failed
(darktable-bin:24912): Gdk-*WARNING***: GdkQuartzDisplay does not
implement the monitor vfuncs
Lua seems to work
Tobias Ellinghaus
2017-01-10 22:26:13 UTC
Permalink
Post by J Albrecht
Post by Tobias Ellinghaus
darktable --luacmd 'print("Lua seems to work")'
Indeed, albeit after some worrisome gtk warnings, the line was printed

[...]
Post by J Albrecht
Lua seems to work
Great. Now we just have to find out why scripts don't work. When you add the
print("foo...") to the very start of ~/.config/darktable/luarc, does that
result in something being printed? If not then try adding "-d lua" to the
darktable arguments.
David Vincent-Jones
2017-01-10 22:33:31 UTC
Permalink
darktable -d lua ... now does print foo...

but I also get an error message "LUA ERROR :
/home/david/.config/darktable/lua/selection_to_pdf.lua:31: Module
selection_to_pdf is not compatible with API 4.0.0

David
Post by Tobias Ellinghaus
Post by J Albrecht
Post by Tobias Ellinghaus
darktable --luacmd 'print("Lua seems to work")'
Indeed, albeit after some worrisome gtk warnings, the line was printed

[...]
Post by J Albrecht
Lua seems to work
Great. Now we just have to find out why scripts don't work. When you add the
print("foo...") to the very start of ~/.config/darktable/luarc, does that
result in something being printed? If not then try adding "-d lua" to the
darktable arguments.
William Ferguson
2017-01-11 00:40:15 UTC
Permalink
Hi David,

Your selection_to_pdf.lua script is outdated. You can get the current one
at
https://raw.githubusercontent.com/darktable-org/lua-scripts/master/official/selection_to_pdf.lua
.
<https://github.com/darktable-org/lua-scripts>
<https://github.com/darktable-org/lua-scripts/tree/master/official>
Darktable 2.2.x uses API 4.0.0, so if you see that message with other
scripts, you need to update them too

Bill
Post by David Vincent-Jones
darktable -d lua ... now does print foo...
Module selection_to_pdf is not compatible with API 4.0.0
David
darktable --luacmd 'print("Lua seems to work")'
Indeed, albeit after some worrisome gtk warnings, the line was printed

[...]
Lua seems to work
Great. Now we just have to find out why scripts don't work. When you add the
print("foo...") to the very start of ~/.config/darktable/luarc, does that
result in something being printed? If not then try adding "-d lua" to the
darktable arguments.
____________________________________________________________________________
darktable user mailing list to unsubscribe send a mail to
J Albrecht
2017-01-10 23:51:52 UTC
Permalink
Post by Tobias Ellinghaus
try adding "-d lua" to the
darktable arguments.
This threw an error:
LUA ERROR : /Users/heviiguy/.config/darktable/luarc:1: syntax error near char(226)

Here’s my luarc:
print(“foo”)
William Ferguson
2017-01-11 02:06:45 UTC
Permalink
It appears that there is a special character in the file which is causing
the lua interpreter problems. Remove, or rename, the current luarc file
and create a new one with

echo 'print("foo")' > ~/.config/darktable/luarc

and try that

Bill
Post by Tobias Ellinghaus
try adding "-d lua" to the
darktable arguments.
LUA ERROR : /Users/heviiguy/.config/darktable/luarc:1: syntax error near char(226)
print(“foo”)
Tobias Ellinghaus
2017-01-11 09:27:12 UTC
Permalink
Post by J Albrecht
Post by Tobias Ellinghaus
try adding "-d lua" to the
darktable arguments.
LUA ERROR : /Users/heviiguy/.config/darktable/luarc:1: syntax error near char(226)
print(“foo”)
Those are typographical quotation marks. Did you use some wordprocessor like
LibreOffice to edit the file?
J Albrecht
2017-01-11 15:05:00 UTC
Permalink
Post by Tobias Ellinghaus
Those are typographical quotation marks. Did you use some wordprocessor like
LibreOffice to edit the file?
No, not LO but rather the simple Mac OS-bundled text editor. Oops.

After wiping out the old luarc, replacing it with one freshly written in TextWrangler and running the command again, I had to let out a secular “Hallelujah!” because, it worked! It even continued to work after adding a few “require”s. Many thanks, Tobias and Bill, for your support :-)

I suppose that in the greater Scheme Of Things, using a proper text editor can be considered by some as fundamental as ensuring that the computer is plugged into a power supply. Alas, for those of us who just want to edit some Raw photos, it’s not very obvious. Thankfully we are part of a great community of experts who graciously offer their support without the patronising arrogance which we often run into in other areas. Thanks again, gentlemen!
Loading...