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.

garry23

David

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

Cheers

Garry

warnotte

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

@warrnotte

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

Cheers

Garry

warnotte

Perfect, I'll have to try this weekend or as soon as possible :)

Thanks Garry.

garry23

...and of course you need ML loaded  ;)

eraizgn

what is exactly the Lua doing with ML? I didnt get it..
just a program for scripting?

garry23

@eraizgn

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

eraizgn


a1ex

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

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

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

...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

The events are defined as LUA_CBR_FUNC.

The ones that are not available are:

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

@A1ex

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

garry23

@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.


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

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

@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:

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).

local ok = lens.focus(-1,1,false)

I'll carry on playing in my own incompetent way ;)

a1ex

Quote from: a1ex on January 13, 2017, 11:46:14 AM
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

Sorry for not getting back: I've been trying to understand what is going on.

I've used this simple test script:

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

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

Do the focus commands work better on EOS M on that branch? You may need to hack it a bit to compile though.

garry23

A1ex/David

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

No C compiling...at least not yet.

Cheers

Garry

a1ex

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

@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

Made a few updates; latest docs are here. Please review, also considering this discussion.