End script in Lua - LUA Scripting - CHDK Forum supplierdeeply

End script in Lua

  • 11 Replies
  • 13019 Views
*

Offline fudgey

  • *****
  • 1705
  • a570is
End script in Lua
« on: 18 / October / 2008, 09:51:42 »
Advertisements
I'm a compete noob with Lua but I'm in the process of improving fbonomi's sunset script a little bit (to remove the need for sleep to make the dark/bright frame toggle phenomenon go away and to optimize sample rate for long exposures).

Now, how does one end a Lua script cleanly somewhere in the middle? end, return, exit...? Like, I want to do something like

Code: [Select]
if get_propset()==1 then
  prop_coming_tv=69
  prop_coming_sv=73
elseif get_propset()==2 then
  prop_coming_tv=262
  prop_coming_sv=247
else
  print("Unsupported propset " .. get_propset())
  print("!! ERROR ERROR !!")
  return
end

without spending a day figuring out just how to formulate all loops in an elegant way that will cause the script to exit from the end...


And another question...after taking a look at the Lua manual, what's the difference/similarity between the following two?:
Code: [Select]
variable::=1
variable=1
« Last Edit: 18 / October / 2008, 10:42:33 by fudgey »

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: End script in Lua
« Reply #1 on: 18 / October / 2008, 11:33:52 »
Quote
...
prop_coming_tv=262

shall i add these as lua/ubasic commands so you dont have to do the checks?

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: End script in Lua
« Reply #2 on: 18 / October / 2008, 11:56:22 »
« Last Edit: 18 / October / 2008, 11:58:19 by fbonomi »

Re: End script in Lua
« Reply #3 on: 19 / October / 2008, 02:24:48 »
"return" can be used to exit the main script.
As well as the error function probably.


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: End script in Lua
« Reply #4 on: 19 / October / 2008, 11:37:20 »

*

Online reyalp

  • ******
  • 13353
Re: End script in Lua
« Reply #5 on: 19 / October / 2008, 18:05:24 »
Quote
...
prop_coming_tv=262

shall i add these as lua/ubasic commands so you dont have to do the checks?
We should probably make all the propcase constants available in some way. It  would be easy enough to do in a lua module (which if you are clever could be auto-generated at build time)
Don't forget what the H stands for.

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: End script in Lua
« Reply #6 on: 20 / October / 2008, 02:54:54 »
well, i know that some propcases that are known in digicII are NOT known in the digicIII environment (yet), i defined them with crazy values (which is not nice), but avoids extra checking. maybe these missing values ( /trunk/include/platform.h - chdk - Trac for example in line 118 and starting in #124) can be found? maybe they ARE found but the wiki isnt updated yet? dont own dryos so i cant test it.
anyhow, i never tapped into the lua sources up to now, so someone else should do it and include the missing ubasic commands/the stuff reyalp proposed (auto-generated).

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: End script in Lua
« Reply #7 on: 20 / October / 2008, 13:58:15 »
well, i know that some propcases that are known in digicII are NOT known in the digicIII environment (yet), i defined them with crazy values (which is not nice), but avoids extra checking. maybe these missing values ( /trunk/include/platform.h - chdk - Trac for example in line 118 and starting in #124) can be found? maybe they ARE found but the wiki isnt updated yet? dont own dryos so i cant test it.
anyhow, i never tapped into the lua sources up to now, so someone else should do it and include the missing ubasic commands/the stuff reyalp proposed (auto-generated).

I believe most Digic III propcases were searched using the vxworks camera a570is (it being the first ported d3 cam) and I don't know if we have found any differences in procases between Digic III cameras that run dryos and vxworks.

PROPCASE_BRACKET_MODE

AFAIK, my a570 has no built-in bracketing without CHDK. Do many Digic II cameras have bracketing? Maybe an s5is user could try searching for this one?

Those flash modes are listed in http://chdk.wikia.com/wiki/PropertyCase nowadays:

121   RW   Flash adjust mode (0=Auto, 1=Manual (see 127&141)
127   RW   Flash exposure compensation (units: +/- 96 per 1 stop range, if #121=0)
141   RW   Manual flash output (units 0,1,2 from min to full, if #121=1)

That focus propcase may not have been searched by anyone so far.
edit: oh sorry... looks like it's #18 but read the note about aiaf.

What reyalp ment with the lua library was probably a clear text file A/CHDK/lualib/propcases.lua, which would not increase CHDK memory footprint. A file which would ideally be created by a script during make, but could just as well be cut&pasted and edited once and updated when need be. I already wrote one with a few propcases for my experiments but didn't quite name them exactly as CHDK's #defines but could just as well.

My approach is not incredibly smart since it creates a new variable for each propcase once called. Fine for one script, no good for all known property cases. Maybe a wrapper function that matches name string and calls set_prop() accordingly would be better, i.e. set_propcase("QUALITY", 1) instead of my current set_prop(PROPCASE_QUALITY, 1)

But with our number of propcases, that set_propcase() function would probably end up taking more than 1000 lua VM instructions and thus >10 ms unless we split it into more than one library function.


In general, at least for Lua we should probably refrain from creating many more functions for propcases, since they are so easily written in library code that doesn't increase size of CHDK and likely executes sufficiently fast (http://chdk.setepontos.com/index.php/topic,1194.msg22785.html#msg22785). Of course, that only applies for functions that allow "raw" access to those propcases, without checking for flash status or something else that may be important in order to avoid crashes and not easily made accessible to Lua.
« Last Edit: 20 / October / 2008, 14:03:42 by fudgey »


*

Offline fe50

  • ******
  • 3132
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: End script in Lua
« Reply #8 on: 20 / October / 2008, 17:04:01 »
...That focus propcase may not have been searched by anyone so far.
edit: oh sorry... looks like it's #18 but read the note about aiaf....

#18 works fine with Digic III cams:
0 = no focus, focus "box" is white or orange (after half-press)
always > 1 when the cam has successfully focused (with green focus "box")

The value #18 returns when focused with AiAf or non-centered AF depends on the position and the count of the focused areas ("boxes"), it's always > 0...

Perhaps somebody finds out the magic behind the value some day...maybe we can manipulate the values to move the focus bracket manually...

*

Online reyalp

  • ******
  • 13353
Re: End script in Lua
« Reply #9 on: 21 / October / 2008, 00:35:17 »
What reyalp ment with the lua library was probably a clear text file A/CHDK/lualib/propcases.lua, which would not increase CHDK memory footprint. A file which would ideally be created by a script during make, but could just as well be cut&pasted and edited once and updated when need be. I already wrote one with a few propcases for my experiments but didn't quite name them exactly as CHDK's #defines but could just as well.
Precisely. Other useful constants from CHDK could be handled the same way.

Quote
My approach is not incredibly smart since it creates a new variable for each propcase once called. Fine for one script, no good for all known property cases. Maybe a wrapper function that matches name string and calls set_prop() accordingly would be better, i.e. set_propcase("QUALITY", 1) instead of my current set_prop(PROPCASE_QUALITY, 1)

But with our number of propcases, that set_propcase() function would probably end up taking more than 1000 lua VM instructions and thus >10 ms unless we split it into more than one library function.
use metamethods so you can do
propcases.quality = X ;)

table lookup is only a couple instructions, so there's no way it should require  1000 :) (that's an arbitrary limit anyway, if it becomes a problem it isn't that hard to work around)

Doing some stuff along these lines is actually on my TODO list, but as you may have noticed, I've been able to devote much time to CHDK in the last couple weeks. I have several things in mind that will become standard lua modules in the CHDK distribution. Then people can just require what they need, and we don't have to bloat the chdk core.
Don't forget what the H stands for.

 

Related Topics