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

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #25 on: April 12, 2015, 02:40:34 AM »
A. There's currently no way to do this.

2. Hint: If a script doesn't load, check the console for errors. (I might also suggest a script editor that does syntax checking, such as: http://www.eclipse.org/ldt )

surami

  • Member
  • ***
  • Posts: 115
Re: LUA Scripting (lua.mo)
« Reply #26 on: April 18, 2015, 09:49:25 PM »
@dmilligan: Could you please help me out, that how could I update the Force Delay script for working well with the updated LUA module?

550D + nightly ML

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #27 on: April 18, 2015, 10:33:19 PM »
Ah, yes, I changed the event API slightly:

Code: [Select]
force_delay_menu = menu.new
{
parent = "Intervalometer",
name = "Force Delay",
help = "Add an extra delay to each interval",
min = 0,
max = 300,
unit = UNIT.TIME,
}

event.intervalometer = function(count) msleep(force_delay_menu.value * 1000) return true end


surami

  • Member
  • ***
  • Posts: 115
Re: LUA Scripting (lua.mo)
« Reply #28 on: April 19, 2015, 12:40:50 AM »
Thanks, I will try as soon as I can compile a new build from the LUA repository.
550D + nightly ML

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #29 on: April 25, 2015, 05:34:14 AM »
Just an update:

The API is really coming together, and is more or less complete and working. So I've started working on an in camera text editor written in lua: https://bitbucket.org/hudson/magic-lantern/commits/9c47101480ce7a1e64152a40666c3373d37c8e87 It's very preliminary at this point, you can select files and view them, but it shouldn't be too much longer until it's a fully functioning editor with the ability to insert text and save files. Thanks to lua's regex like capabilities, cool things like syntax coloring and basic auto-complete shouldn't be too hard either, and with lua's built-in debugging capabilities, things like setting breakpoints, stepping through code and an "immediate console" are also possibilities.

Audionut

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3657
  • Blunt and to the point
Re: LUA Scripting (lua.mo)
« Reply #30 on: April 25, 2015, 09:09:43 AM »
In camera editing with some stupidity debugging sounds great.

Looking forward to trying this out.

nikfreak

  • Developer
  • Hero Member
  • *****
  • Posts: 1197
Re: LUA Scripting (lua.mo)
« Reply #31 on: April 25, 2015, 10:10:42 AM »
you have been definitely been on a run getting LUA to work on ML. Chapeau! Checking how chdk people use lua for scripting this will definitely help lots of people.
70D.112 & 100D.101

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 3401
  • 5D3 | M1 | 7D | 70D | SL1 | M2 | 50D
Re: LUA Scripting (lua.mo)
« Reply #32 on: April 25, 2015, 10:23:01 AM »
Run, David, Run!  8)
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

EBurke

  • Just arrived
  • *
  • Posts: 1
Re: LUA Scripting (lua.mo)
« Reply #33 on: April 30, 2015, 12:22:11 PM »
I am new to ML and have little background in Lua. I am excited that I am going to learn both soon.

I have installed ML on a 5D2 camera through standard build. Reading the posts here I assume I have to replace it with a Lua compatible build. Is there a link to an already existing build or I must build it from the source, is it sufficient to try and build lua branch?

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #34 on: April 30, 2015, 04:36:18 PM »
@EBurke,
correct, see the OP



Updates:

Yesterday, I managed to write a script and then debug/step through it entirely in camera! (and all of this from a program that is itself just a lua script!) This is very cool and exciting (and quite meta!), there are many possibilities...


garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2217
Re: LUA Scripting (lua.mo)
« Reply #35 on: April 30, 2015, 04:48:08 PM »
@dmilligan

As you say, this is really exciting.

Like others, I'm sure, I'm waiting for the sign (from the coders/gurus above) that things are stable enough to begin 'playing'.

Thanks for all your efforts (and those others that are adding value here).

 :)


g3gg0

  • Developer
  • Hero Member
  • *****
  • Posts: 3182
Re: LUA Scripting (lua.mo)
« Reply #36 on: May 01, 2015, 08:54:30 PM »
@dmilligan:

do you need some changes to IME for integrating it into your editor?
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: paypal@g3gg0.de
ONLY donate for things we have done, not for things you expect!

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #37 on: May 02, 2015, 08:41:36 PM »
no, I think I prefer just doing my own input in lua, I already have stuff like copy and paste, and I'll probably be working on things like autocomplete. Eventually a lot of the code from the editor could become a high-level, object-oriented UI API for lua.

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #38 on: May 09, 2015, 09:39:55 PM »
Updates:

Most floating point stuff seems to be working now (previously, parsing and printing floats would crash the interpreter due to some non-standards-compliant libc functions).

Keep in mind that doing floating point math can be quite slow. Fortunately for us, new in lua 5.3 is a lot of stuff for doing integer only math. For example // will do integer division (a normal single / will automatically promote to floating point).

I have improved the API for basic exposure settings with various units (some floating point, some integer).
So now instead of camera.shutter you have the following:

camera.shutter.raw
camera.shutter.apex
camera.shutter.apexf
camera.shutter.ms
camera.shutter.value
camera.shutter:tostring()

aperture, iso, and ec also follow the same basic pattern. See the updated docs for more info.

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 3401
  • 5D3 | M1 | 7D | 70D | SL1 | M2 | 50D
Re: LUA Scripting (lua.mo)
« Reply #39 on: May 09, 2015, 11:35:09 PM »
All this is looking positive so far... Keep up the great work everyone!
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

Totte

  • New to the forum
  • *
  • Posts: 26
Re: LUA Scripting (lua.mo)
« Reply #40 on: May 10, 2015, 11:03:32 AM »
How is the program control in modules in general and in this LUA implementation in particular? Is the LUA script in full control when it is running or are there system tasks that can mess up the timing of simple LUA while loops and/or timer interrupts? I can see this replacing the advanced intervalometer module completely for my kind of use, if timing can be trusted.

chris_overseas

  • Moderators
  • Member
  • *****
  • Posts: 234
Re: LUA Scripting (lua.mo)
« Reply #41 on: May 10, 2015, 11:18:24 AM »
There's a minor bug in the docs I think: The docs for ec.raw and ec.apex both refer to aperture rather than exposure compensation.

This module is looking impressive dmilligan, I'm looking forward to trying it out properly.
EOS R5 1.1.0 | Canon 16-35mm f4.0L | Tamron SP 24-70mm f/2.8 Di VC USD G2 | Canon 70-200mm f2.8L IS II | Canon 100-400mm f4.5-5.6L II | Canon 800mm f5.6L | Canon 100mm f2.8L macro | Sigma 14mm f/1.8 DG HSM Art | Yongnuo YN600EX-RT II

pholler

  • Freshman
  • **
  • Posts: 93
Re: LUA Scripting (lua.mo)
« Reply #42 on: May 10, 2015, 04:46:57 PM »
Hi David,

i am still working on my intervalometer-script. At the moment i want to manipulate the shutter speed that is determined by AETTR. The idea is that small changes in shutter speed are ignored.
The thing is that i cannot manage to do operations directly after a shooting-task. The following code is not started after pressing the shutter or using the intervalometer. I don't know why. Could you give me hint?
Code: [Select]
function event.post_shoot()
print("post_shoot()")
end

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #43 on: May 11, 2015, 03:56:37 AM »
@chris_overseas,
yes, thanks, there are probably lots of typos in the docs (lots of copy/pasting). Every time I go back and read them it seems I find another typo.

@pholler,
it appears that cbr (as well as pre_shoot) is not actually implemented in the ML core, it's a simple fix, I will probably submit a patch to the main branch

@Totte,
It would certainly be possible to to implement the advanced intervalometer as script (in fact that was one of my goals when working on the API: what would I need to completely re-implement it in lua). Actually doing the re-implementation may take some time (it's sort of a low priority, but it's a good test case for the lua engine). Unless you're doing some really heavy processing (i.e. image analysis), I don't think "timing" is going to be an issue. Lua performance is actually pretty good. The text editor I wrote in lua does a lot of drawing and it works pretty smoothly.

Totte

  • New to the forum
  • *
  • Posts: 26
Re: LUA Scripting (lua.mo)
« Reply #44 on: May 11, 2015, 02:26:19 PM »
Just to clarify, I'm not asking for a re-implementation of the advanced intervalometer in LUA just because it can be done (although that is usually reason good enough ;)). For me, writing a script will be much simpler than to generate a complex exposure sequence in the AI. And the scripts can also easily be saved and loaded again from the camera.

I'm looking at taking pictures with sub-second timing resolution. What worries me is whether the length of while-loops or msleep(ms) could possibly be unpredictable because other system tasks have priority when scripts are running? No processing involved for me, just set new exposure values, wait and fire again.

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #45 on: May 11, 2015, 04:02:03 PM »
For simple things, I doubt you would be able to notice much difference between doing something in lua or doing it in native C. Also, most of the time spent for simple stuff is likely going to be in the API call itself, not your script code. You also have access to the vast majority of the ML core API calls, and if there's something in particular you need that's missing, it's pretty easy to add.

I see no reason you couldn't achieve pretty accurate timing in a script, but depending on exactly how precise you want it to be, it may be more a little more complicated than simply calling msleep in a while loop (which is what it sounds like you are asking). The issue there wouldn't really be the fact that it's a script, but simply the naïve approach to timing. However, the timing should be halfway decent even with a naïve approach like this, you're just probably going to see "drift" over time. More robust scenarios are certainly possible, and creating simple constructs for them in the API is also a possibility.

Alternatively, you can piggyback the existing ML intervalometer and modify it's behavior, or you have event.seconds_clock cbr, or you also have access to a milliseconds clock.

pholler

  • Freshman
  • **
  • Posts: 93
Re: LUA Scripting (lua.mo)
« Reply #46 on: May 20, 2015, 09:39:04 PM »
Hi David,

i read all your docu and alle the menu-samples but i still can't get the following thing working. I want a menu whos parent is "Intervalometer". When you press that menu it activates or deactivates the function. In the submenu i need decimal values to choose the minimal interval and to choose the minimal processing time between two shots. This can either be a decimal number or a time value. I tried it several times but i fail implementing such a menu structure. Could you give me a sample how to do that?

Best regards

Peter

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: LUA Scripting (lua.mo)
« Reply #47 on: May 21, 2015, 05:42:28 PM »
It's not possible for items in a submenu to exhibit this behavior. Submenus can have submenus but if they do, they can't toggle their own values too (because SET goes into the submenu and Q goes back out). You have to make a submenu item for enabling/disabling the feature.

Code: [Select]
mymenu = menu.new
{
    parent = "Intervalometer",
    name = "Whatever",
    update = function(self) return self.submenu["Enabled"].value end
    submenu =
    {
        {
            name = "Enabled",
            choices = {"Off","On"},
        },
        {
             name = "Dec. Value",
             min = 0, max = 500,
             unit = UNIT.DEC,
         },
        {
             name = "Time Value",
             min = 0, max = 500,
             unit = UNIT.TIME,
         }
    }
}

pholler

  • Freshman
  • **
  • Posts: 93
Re: LUA Scripting (lua.mo)
« Reply #48 on: May 21, 2015, 07:08:24 PM »
Thanx david! With your input i just finished my intervalometer-script:
http://www.magiclantern.fm/forum/index.php?topic=15119.0

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2217
Re: LUA Scripting (lua.mo)
« Reply #49 on: May 25, 2015, 03:59:52 PM »
@dmilligan

Can you point me to the source where you code the various Lua functions and fields.

I tried looking in your bitbucket link but could find the source.

I'm trying to educate myself as to how you created the Lua to ML links, eg lens control.

Cheers