Author Topic: Lua Scripting (lua.mo)  (Read 85764 times)

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #200 on: October 30, 2016, 10:20:00 PM »
David

Thanks for the pointer: just downloaded visualstudio and will report any 'strangeness'.

Cheers

Garry

warnotte

  • New to the forum
  • *
  • Posts: 9
Re: Lua Scripting (lua.mo)
« Reply #201 on: December 02, 2016, 03:05:09 PM »
Damn, that looks a pretty cool stuff.

One question (perhaps already asked, I'm sorry if it's the case) :

So I can code my LUA file, then put it directly on the card without have to compile something and the LUA module will interpret it ? (I shorten the description a little bit).

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #202 on: December 02, 2016, 04:01:26 PM »
@warrnotte

Yes. Just code lua in a text file and ensure file extension is .lua  :)

Cheers

Garry

warnotte

  • New to the forum
  • *
  • Posts: 9
Re: Lua Scripting (lua.mo)
« Reply #203 on: December 02, 2016, 04:18:29 PM »
Perfect, I'll have to try this weekend or as soon as possible :)

Thanks Garry.

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #204 on: December 02, 2016, 04:29:58 PM »
...and of course you need ML loaded  ;)

eraizgn

  • Freshman
  • **
  • Posts: 56
Re: Lua Scripting (lua.mo)
« Reply #205 on: December 03, 2016, 09:30:05 AM »
what is exactly the Lua doing with ML? I didnt get it..
just a program for scripting?

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #206 on: December 03, 2016, 10:16:41 AM »
@eraizgn

The ML Lua module is 'simply' a Lua interpreter that the ML environment provides. With Lua you can code Lua scripts  ;)

eraizgn

  • Freshman
  • **
  • Posts: 56
Re: Lua Scripting (lua.mo)
« Reply #207 on: December 10, 2016, 09:15:00 PM »
thank you man!

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #208 on: January 13, 2017, 12:45:39 AM »
Added builds from the lua_fix branch to https://builds.magiclantern.fm/experiments.html

The current state looks pretty good to me; if there are no obvious issues, I think it's ready to be merged into nightly.

Updated API docs here (though it won't be the final location).

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #209 on: January 13, 2017, 08:20:22 AM »
A1ex

Fantastic. I'll do testing/evaluation this weekend and report back.

Once again, thanks to everyone involved, for all the hard work on Lua.

Cheers

Garry

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #210 on: January 13, 2017, 08:44:17 AM »
A1ex

Just noticed that 5D.123 is not there.

If it is not too much trouble, when you get a chance, could you throw in a Lua experimental build for the 5D.123 as well?

I currently use .123 as I need the F/8 focus for my 70-200 F/4L x2 ;)

Cheers

Garry

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #211 on: January 13, 2017, 08:57:11 AM »
...also

As I've tried to use each update of Lua, I've looked at the Lua .c files to try and work out the changes. I say tried, as I'm not a C programmer.

I have done this as David warned me that not all Lua functions are enabled, eg some of the event.x calls.

One thing that confuses me is that I can't find event.c to look for these calls, ie to see what is implemented.

The manual doesn't say "Not Implemented Yet".

As I'm not the developer, I, of course, don't know what is developed or switched on, without looking. Which, as I say, I try to do, but event.c evades me  ;)

Any hints/help would be great, as I try and evaluate the latest Lua_fix experimental build, eg what is not yet enable but is in the manual.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #212 on: January 13, 2017, 09:40:49 AM »
The events are defined as LUA_CBR_FUNC.

The ones that are not available are:
Code: [Select]
LUA_CBR_FUNC(pre_shoot, ctx, 500)
LUA_CBR_FUNC(post_shoot, ctx, 500)

#ifdef CONFIG_VSYNC_EVENTS
LUA_CBR_FUNC(vsync)
LUA_CBR_FUNC(display_filter)
LUA_CBR_FUNC(vsync_setparam)
#endif

The first two are not yet available from ML core. For pre_shoot, we don't know yet where to place a hook in order to do something useful from it (such as update exposure settings, or prevent the picture from being taken), so it requires reverse engineering. The post_shoot hook is a bit ill-defined, as it's a bit hard to tell when exactly a picture is finished, especially in burst mode. Currently, most ML code uses the QuickReview screen to tell whether a picture was taken; the recent Burst module looks at the file number property from Canon, which appears to work fine.

The last 3 are from LiveView vsync hook, which must be fast; otherwise it can interfere with image capture, possibly resulting in corrupted frames. Since the pink frames still appear during raw recording, it's probably best to keep those disabled, unless there's a good reason to use them.

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #213 on: January 13, 2017, 09:53:04 AM »
@A1ex

Many thanks: this info will help me as I try and do Lua experiments/exploration  :)

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #214 on: January 13, 2017, 11:35:07 AM »
@A1ex

Before I 'waste' time, I'm guessing the experimental Lua_fix hasn't fixed lens move on the EOSM?

Just tried this simple test script and all I get in the no movement and rapid yellow blinking shutter button.

Code: [Select]
function event.keypress(k)
    if k == KEY.INFO then
        repeat
lens.focus(-1,1,false)
until lens.focus_distance >= lens.hyperfocal
    return false
    else
        return true
    end
end

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #215 on: January 13, 2017, 11:46:14 AM »
You confirmed it's working here. There should be no difference between the two branches, regarding focus backend.

BTW, focus commands should not be sent from GUI task.

Sorry, can't help much more than that...

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #216 on: January 13, 2017, 12:59:23 PM »
@A1ex

I'm testing things on a 5D3 and an EOSM, with Canon Lens and Sigma Lens, and with Canon adapter and non-canon adapter on the EOSM  ::)

I'm now using this test script:

Code: [Select]
function test_lens()
        repeat
           lens.focus(-1,1,false)
        until lens.focus_distance >= lens.hyperfocal
end

test_menu = menu.new
{
    parent = "Shoot",
    name = "Test Lens Move",
depends_on = DEPENDS_ON.LIVEVIEW,
    submenu =
{
{
name = "Run Script",
help = "Does what it says after pressing SET",
depends_on = DEPENDS_ON.LIVEVIEW,
select = function(this) task.create(test_lens) end,
}
    }
}

The above runs OK on the 5D3 with all AF lenses.

I doesn't seem to run on the EOSM with any AF lens. But it's flaky. For example, it did run once, but with incredibly small focus steps.

Also, and I'm sure it's my programming again, on the above script I get 0 or 1 sometimes returned on the menu, when the lens is being moved.

I've tried using lens focus this way, but still get the menu feedback (to the right of the menu).

Code: [Select]
local ok = lens.focus(-1,1,false)
I'll carry on playing in my own incompetent way ;)

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #217 on: January 13, 2017, 03:01:52 PM »
You confirmed it's working here.

In other words: does this script work on the build you have tried there, but not on the latest lua_fix?

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #218 on: January 13, 2017, 03:44:33 PM »
Sorry for not getting back: I've been trying to understand what is going on.

I've used this simple test script:

Code: [Select]
function test_lens()
    local start = lens.focus_distance -- position lens near macro end
        repeat
           lens.focus(-1,1,false)
        until lens.focus_distance >= lens.hyperfocal
        -- now go back
        repeat
           lens.focus(1,1,false)
        until lens.focus_distance <= start
end

test_menu = menu.new
{
    parent = "Shoot",
    name = "Test Lens Move",
    submenu =
{
{
name = "Run Script",
help = "Does what it says after pressing SET",
select = function(this) task.create(test_lens) end,
}
    }
}

I proved this script runs as expected on my 5D3 using the latest nightly .123 build (sic). I used a Sigma 10-20 to test the script.

I then used the script (with no other scripts running) on the experimental EOSM Lua_fix build.

The lens starts to move from its initial position towards infinity, but using very small/micro steps (I'm using the 24-105 F/4L at 24.

It doesnt stop at the hyperfocal (as with the 5D3) and keeps going until soft-limit error, ie doesn't do the return to the start, as it should.

That's it so far :(

Cheers

Garry

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3203
  • 60Da / 1100D / EOSM
Re: Lua Scripting (lua.mo)
« Reply #219 on: January 13, 2017, 05:41:13 PM »
The new focus stuff is not included in this branch yet. EOSM still needs some work on the focus branch too (https://bitbucket.org/hudson/magic-lantern/pull-requests/748)

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #220 on: January 13, 2017, 05:48:28 PM »
Do the focus commands work better on EOS M on that branch? You may need to hack it a bit to compile though.

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #221 on: January 13, 2017, 05:54:57 PM »
A1ex/David

Sorry, I'm 'only' fit for scripting...and only just  ;)

No C compiling...at least not yet.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #222 on: January 24, 2017, 04:53:35 PM »
Noticed there are two APIs for taking a picture: shoot() and camera.shoot(). Obviously, they are out of sync, as I've been only updating the latter.

Additionally, there are also camera.bulb() and camera.burst().

What's the best way to fix?

- keep the two in sync by calling the same function (would still require duplicate documentation)
- remove shoot() and leave just camera.shoot()
- move all others to global namespace

garry23

  • Hero Member
  • *****
  • Posts: 1280
Re: Lua Scripting (lua.mo)
« Reply #223 on: January 24, 2017, 05:30:49 PM »
@A1ex

I personally always use camera.shoot() and test if I need to use camera.bulb().

My gut feeling is that those writing, and publishing scripts, would defer to the guidance/views of people like yourself. Including what approach is best for you to implement.

As I said in another post, the main issues at the moment are around guessing what some Lua calls actually mean/require and what simply is not active yet, but appears in the documentation. 

As usual, just my humble views.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10342
  • 5D Mark Free
Re: Lua Scripting (lua.mo)
« Reply #224 on: January 25, 2017, 02:35:29 AM »
Made a few updates; latest docs are here. Please review, also considering this discussion.