Lua Scripting (lua.mo)

Started by dmilligan, March 29, 2015, 04:44:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Licaon_Kter


Quote from: Totte on June 09, 2015, 08:48:43 PMThat makes sense, except that I don't see any trace of copy2m.
Read the source and it says were the menu item should appear.


copy2m_menu = menu.new{
parent = "Prefs",
name = "Copy To M",
...
}

Totte

Thanks to both of you, I can confirm that I see the other scripts now.

In the console I get a bunch of 404's at startup before "Modules loaded":
auto_ettr_intervalometer_wait
dual_iso_get_dr_improvement
dual_iso_get_recovery_iso

There could be more, I just see it slowly printing auto_ettr_intervalometer_wait, then quickly overwriting it with the next two function names. Any idea where this comes from?

In the editor I am simply stuck as the Picture style button (which is supposed to be Q on the 5D2) does not open the menu. Key translation missing?

pholler

Hi David,

do you think it's possible use a LUA-script to use focus-trap onlny when the shutter-button ist clicked and AF-assist when you press the AF-on-button. I described it in more detail here: http://www.magiclantern.fm/forum/index.php?topic=14914.msg145552#msg145552.

dfort

I'm trying to track down properties that trigger the shutter-bug on the EOS-M. There's a tool for that (property spy) but it is not working on the EOS-M so I'm looking into trying to do it in a lua script. No problem getting the lua branch working though I did have problems writing scripts with various text editors, I kept getting errors on start up:
Loading script: propspy.lua
ML/SCRIPTS/propspy.lua:11: unexpected symbol near '<\226>'
Loading script: ._propspy.lua
ML/SCRIPTS/._propspy.lua:1: unexpected symbol

Switching over to the nano text editor solved that problem. Yeah, I know, real programmers use vi or emacs.

Anyway, the script is very simple, basically a modified "Hello, World!" script.
-- Spy on a Property

function property.LENS_SOMETHING:handler(value)
    print("Lens Something: "..value)
end

function main()
    menu.close()
    console.show()
    print "Property Spy"
    print(property.LENS_SOMETHING)
    print "Half-press shutter to exit."
    key.wait()
    console.hide()
end

keymenu = menu.new
{
    name = "Property Spy",
    select = function(this) task.create(main) end,
}



The output printed on the console is:
Save configs...
Property Spy
table: p
Half-press shutter to exit.

This is my first attempt at writing a script. I checked the online tutorials but haven't been able to figure it out. Any clues to what I'm doing wrong?

dmilligan

You can't retrieve the value of a property with Lua like this. All you can really do is set a property change handler (you can request a change if you enable this functionality, see the warning in the docs).

dfort

You mean this warning?

// !!!DANGER WILL ROBINSON!!!
//#define LUA_PROP_REQUEST_CHANGE


Yeah, I'm a little hesitant turning that on. So in your example:

function property.SHUTTER:handler(value)
     print("shutter: "..value)
end


You need to have #define LUA_PROP_REQUEST_CHANGE enabled for it to work?

Calling the function like this would then print to the console when there's a change in the shutter, like when firing off a shot or doing a shutter half-press?

function property.SHUTTER:handler(value)
     print("shutter: "..value)
end

function main()
    menu.close()
    console.show()
    property.SHUTTER
end


Just checking before I try it. I've got 3 EOS-M's so I've got 3 chances to get this right.

Licaon_Kter

My script used to detect shooting mode changes for this bug: https://bitbucket.org/hudson/magic-lantern/issues/2297/shoot-mode-ca-and-hdr-backlight-control


--copies the shutter, aperture, and iso of the current mode when switching to M mode
require("config")


--class to keep track of property values using prophandlers
prop_value = {}
prop_value.__index = prop_value


function prop_value.create(...)
    local pv =
    {
        value = 0,
        previous = 0,
        time = dryos.ms_clock,
        props = {...}
    }
    setmetatable(pv,prop_value)
    return pv
end


function prop_value:enable()
    for i,v in ipairs(self.props) do
        function v.handler(prop,value) self:set(value) end
    end
end


function prop_value:disable()
    for i,v in ipairs(self.props) do
        v.handler = nil
    end
end


function prop_value:set(value)
    if camera.mode ~= MODE.M and value ~= 0 then
        self.previous = self.value
        self.value = value
    end
end


function prop_value:get()
    --ignore value if we've been in the current mode for less than 1 sec
    if dryos.ms_clock - self.time < 1000 then
        return self.previous
    else
        return self.value
    end
end


--will be set as the prop handler for property.SHOOTING_MODE, when enabled
function shooting_mode_handler(self,value)
      print("shutter: "..value)
end


modedisplay_menu = menu.new
{
    parent = "Prefs",
    name = "Mode display",
    help = "Switch mode and print",
    choices = {"Off","On"},
    value = "Off"
}


function modedisplay_menu:select(delta)
    if self.value == "Off" then self.value = "On" else self.value = "Off" end
    modedisplay_update(self.value)
end


--start/stop the prop handlers to enable/disable this script's functionality
function modedisplay_update(value)
    if value == "On" then
        property.SHOOTING_MODE.handler = shooting_mode_handler
    else
        property.SHOOTING_MODE.handler = nil
    end
end


config.create_from_menu(modedisplay_menu)
modedisplay_update(modedisplay_menu.value)



It's a modified script from here: https://davidmilligan.github.io/ml-lua/examples/copy2m.lua.html with lots of cruft.
What you should change is SHOOTING_MODE to whatever property you desire: https://davidmilligan.github.io/ml-lua/modules/property.html
Two tips, never use two scripts with the same menu/function names, it will crash LUA & ML, and second you need /ML/scripts/LIB/config.lua present too.

dmilligan

Quote from: dfort on August 04, 2015, 03:29:36 AM
You need to have #define LUA_PROP_REQUEST_CHANGE enabled for it to work?
No. That is only for if you want to set the value of a property.

You can add a handler that gets called when the property changes without enabling this macro. Using a handler is the only way to get a property value (except for select properties which are exposed other ways like in the 'camera' class). What I meant in my post is that there is no method to retrieve the value of a property on demand. The only way is to set a handler and wait until the property changes.

dfort

Thanks dmilligan and Licaon_Kter, now I get it. Well, sort of. It will be questionable whether the shutter-bug can be tracked down by waiting until a property changes. What's important is finding what state a property is in when the camera is first powered on and compare it to when the shutter-bug is active and inactive. In any case, it is worth looking at what properties change when un-mounting and re-mounting the lens--one of the shutter-bug workarounds.

I must admit that I didn't understand what the copy2m.lua script was doing. It doesn't seem to display anything on the screen or write a log to the card. With Licaon_Kter's modified version it prints to the console so it is clear what is going on and how he was able to find the shooting_mode he was looking for.

Anyway, this is tricky stuff for a beginner like me. Any little change I make to Licaon_Kter's script seems to blow it up. This is going to take me a while--but first I'm going on a vacation so I should have a fresh start on this in a couple of weeks.

By the way--is this the right place to mention bugs or peculiar behavior of lua scripts or should that be done on bitbucket under the "Modules (other module)" component? There isn't one for lua.

dmilligan

Best place to comment is on the current pull request for it on bitbucket.

garry23

Just a quick inquiry regarding progress.

Like many I'm eager to experiment with scripting, but I'm not adept enough at compiling my own (5D3-113 and 50D).

Could I politely ask if there will be any chance of seeing Lua scripting in the nightlies any time soon?

Cheers

Garry

f.javi.pz

Hi,

I'm also eager to experiment with scripting, and as garry23, compiling can be too complicated for me.

I've tried the "codio way" at

http://www.magiclantern.fm/forum/index.php?topic=14725.msg142351#msg142351

but I'm afraid that web has now restrictions (no Terminal tool if you don't have a paid account).

I have access to a linux computer (ubuntu) so...

can anybody please tell me how to compile lua.mo on it's terminal?

I'm afraid I could need a "dummy" approach: "download all the files from this link" and so on.

This is a community project. Although my skills are quite basic, I will contribute with probably World's simplest scrip!  :)

Thank you anyway, your work has been jus amazing (and your patience with newbies like me),

Javi.

Licaon_Kter

This: http://www.magiclantern.fm/forum/index.php?topic=991.0

And the Pull Request patch is this: https://bitbucket.org/api/2.0/repositories/hudson/magic-lantern/pullrequests/642/patch


cd magiclanternfoldername
patch -p0 -i bitbucket-hudson-magic-lantern-pullrequest-642.patch

(or was that p1 ?)

See my notes here too as they might help you if you encounter any errors: https://bitbucket.org/hudson/magic-lantern/issues/2297/shoot-mode-ca-and-hdr-backlight-control#comment-18586259

Then see this: http://www.magiclantern.fm/forum/index.php?topic=14725.msg150244#msg150244

If the dual_iso module fails you need multiarch or just edit line 12 in magiclantern/modules/dual_iso/Makefile like this:
# include Makefile.cr2hdr # means comment out

Walter Schulz

Fireworks, please!
https://bitbucket.org/hudson/magic-lantern/pull-requests/642/lua-scripting/activity#
[Sound]Black Eyed Peas: I Gotta Feeling[/Sound]

Finally! Thanks to all involved!

g3gg0

okay i merged LUA into mainline.

but do me one favor:
integrate IME module (ime_base) for quicker text editing, both in edit view and save box etc.
it is meant to be an ML module so people do not always reimplement the wheel on their own...
you can of course make it optional via menu a la "Insert Text via IME" or an IME button.

description: http://www.magiclantern.fm/forum/index.php?topic=6899.0
code: https://bitbucket.org/hudson/magic-lantern/src/524b2bc791d786bab42d1ec094134613db773b23/modules/ime_base/ime_base.c?at=unified
see ime_base_test_* functions
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

dmilligan

Hooray!

I had been thinking about integrating IME, but it was less work to just do it in pure Lua than expose the IME API :P But I agree there should be a unified text input method, so I will work on it.

g3gg0

thanks a lot.

as said, i am sure they can co-exist (e.g. longpress-Q can open a popup "insert text via IME" or "copy" "paste" stuff etc)
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

f.javi.pz

So...

I've got all the code ready (thanks Licaon_Kter!), Black Eyed Peas are waiting at the living room with lots of fireworks, a lighter and a dangerous look...

I think I have everything, I can compile it. Wait!, it's already done at the mainline!

Thanks Walter, g3gg0, dmilligan!

Licaon_Kter

This fails on my EOS-M with GCC 5.2.1: https://bitbucket.org/snippets/Licaon_Kter/Mdzey

EOSM (localeconv, strspn, memchr)

But it works with GCC 4.8.4 and GCC 4.9.3.


/LE: Reported: https://bitbucket.org/hudson/magic-lantern/issues/2449/lua-module-build-fails-with-gcc-521

axelcine

LUA is a tremendously fine piece of software. I envision - and hope -, that in the near future skilled photographers are going to provide us with libraries of LUA scripts, performing all kinds of tasks like HDR or RAW filming. dmilligan has given us a fine tool.
EOS RP, 5dIII.113/Batt.grip, 5dIII.123, 700d/Batt.Grip/VF4 viewfinder + a truckload of new and older Canon L, Sigma and Tamron glass

Walter Schulz

Dang! It's not the first time I mentioned to suck as a programmer.
Help, please: How to place a new menu item in an existing submenu?
Location should be Prefs tab -> Config files
I learned how to create a new menu item in Prefs tab by
parent = "Prefs";


dmilligan


Walter Schulz

I could swear I tried this tonight but failed. I retried and it works.
Thanks!

Walter Schulz

Always missed the option to reboot from menu in Modules and Prefs -> Config files ...

Reb_Conf.lua
-- Unsophisticated reboot (Prefs -> Config files)

function main()
    camera.reboot()
end

keymenu = menu.new
{
    parent = "Config files",
    name = "Reboot",
    help = "Reboots cam. Will not ask for confirmation!",
    select = function(this) task.create(main) end,
}


Reb_Modu.lua
-- Unsophisticated reboot (Modules)

function main()
    camera.reboot()
end

keymenu = menu.new
{
    parent = "Modules",
    name = "Reboot",
    help = "Reboots cam. Will not ask for confirmation!",
    select = function(this) task.create(main) end,
}



garry23

Walter

Thanks for posting this as it helps people like me, who are keen to start scripting, but, bluntly not programmers and don't know Lua syntax etc.

The more people like me can see others' scripts, the quicker we will be able to write our own scripts.

It truly would be fantastic is someone could write a simple (couple of pages) ML-focused intro to Lua scripting, ie showing how to do all the 'common' things we will be looking to do, eg: set up menu, get focus position, change exposure, move lens focus, take an image, drive other ML functionality from within a script, eg set ETTR etc etc.

Once again: thanks for posting and I hope others do as well.

Cheers

Garry