Implementing scripts in C - Feature Requests - CHDK Forum

Implementing scripts in C

  • 24 Replies
  • 11986 Views
*

Offline RaduP

  • *****
  • 926
Implementing scripts in C
« on: 20 / July / 2008, 20:56:54 »
Advertisements
I was thinking, soem scripts are pretty useful, such as the motion detection and the USB remote scripts. So how about if they are implemented in C, rather than in Basic, and give the user the choice to turn them on/off?
There are a few advantages that way:
1. Faster response (especially useful for remote and motion detection)
2. The ability to execute a script in the case of USB remote or motion detection.
3. No need to load a script for the common used tasks.

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #1 on: 22 / July / 2008, 14:10:24 »
Isn't this basically the sort of thing that the ELF edition would allow (aside from allowing much more)? You can't "script" in C, strictly speaking, unless you write a C interpreter and then put it into CHDK, and then it wouldn't be any faster than uBASIC or Lua. If you're ok with compiled C, though, then dynamic ELF loading sounds just like what's needed.

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Implementing scripts in C
« Reply #2 on: 22 / July / 2008, 14:18:23 »
well, The USB Detection already is in C, it can be used this way in Microfunguys SDM and in the collaborative Build. It sure as hell can be extended to trigger anything you like to be triggered, be it a script or anything else.
motion detection would be really cool if integrated into chdk directly, i dont know how to do that though.
main advantage of the direct integration wouldnt be speed though, it would be usability. you could have a dedicated menu with all the options and the likes. would be really userfriendly. along those lines an integrated intervalometer wouldnt hurt as well ;)
the elf edition would really kick A$$, thats for sure!

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Implementing scripts in C
« Reply #3 on: 22 / July / 2008, 15:48:15 »
Making a new menu won't be an issue. ;)
(Other than it will require some more mem.)
Initializing MD via that menu is easy, too. I guess.
Don't know about e.g. interrupting MD etc.
Would someone like to make the first test? :]
(Or if already done, publish it. ;)

I hope Velo keeps us posted on his latest plans.
(Lua extensions for the win. ;)

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Implementing scripts in C
« Reply #4 on: 22 / July / 2008, 17:39:49 »
I think some widely used scripts could indeed be developed into internal CHDK features. But then again, that takes away the user's power to quickly fiddle with the script code (not everyone wants to compile their own builds I think ;) ) for their specific needs... a script that's hard-coded in C won't probably be available as an uBasic or Lua script with the same functionality.

As for speed, I think Lua mostly solves that by not wasting 10 ms for every variable substitution, rem line etc. For example my MDFB script wouldn't get one bit faster to react if it was entirely coded in C (or Lua for that matter), because mx3's md_detect_motion is C code and does the critical part in detecting and (in fast react mode) pressing the shutter. Stuff that happen after shooting, before MD is rearmed would be done quicker in Lua or C, but that's not a problem except in my newest devel version which has Av/Tv/Ev adjustment for a570is (and is not quickly portable for others thank you for asking, it uses about 10 more propcases, button presses (gasp... if anyone knows how to work SSAPI::EnterToCompensationEVF and SSAPI::ExitFromCompensationEVF found in a570is 1.00e firmware strings, please tell me...) and the uBasic modemap which we don't have, at least for models that have negative modemap values we don't).

What I'd really like to see would be an improvement (for both uBasic and Lua) in the script menu, i.e. ways for the script to define it's script menu appearance to a larger extent. Like
  • submenus (I use intendation, but that's no good really)
  • settings profiles (for this we already have a patch in the juciphox build I think?)
  • enumerated+named and range limited input values like choosing feature YES/NO instead of 1/0 and a comment saying what 1 and 0 mean and having to code input sanitation to the script; this we have in several CHDK menus but a script interface to it is missing; could be something like
    @param a Funky sizzle
    @default a 1
    @enum a 0 "OFF" 1 "ON" -1 "You choose" 2 "Not today".
  • parameter help pages, maybe like
    @help a "Funky sizzle adds the crackle & pop to your holiday photos."
  • a customized script load menu for 10 of my most used scripts (and their previously used parameters or settings profiles would of course be remembered); I'm embarrassed to reveal that I've never tried the custom user menu, maybe it would be good for this?

*

Offline fe50

  • ******
  • 3152
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Implementing scripts in C
« Reply #5 on: 22 / July / 2008, 18:38:37 »
I'd prefer LUA for the upcoming generation of scripting:

CHDK is getting bigger and bigger, the uBasic scripts are getting bigger and bigger - imho ubasic is good for simple & fast scripts, but it's a agony on a big uBasic script working with the labels and jumps/gosubs...
*Edit: with "simple & fast scripts" i meant fast written, not fast in execution...

With LUA we have much more possibilities and coding complex scripts would get easier with real functions and without the uBasic limitations (8kB size, 10ms stepping...).
We can also swap out script code into external libraries, this way within some time we could get great ready-to use libraries which everybody can include in an own script without having hundreds or thousands lines of code in one script file...

With such LUA libraries we could kill two birds with one stone: optimal speed & maximum flexibility !
Experienced users can optimize the programm furthermore in any way, others only have to include the ready-to-use libraries and call the functions they need...

...i also think we need "real" (and unlimited) parameter identifiers, it's a plague with the one-letter params on large scripts...

« Last Edit: 22 / July / 2008, 18:44:31 by fe50 »

*

Offline reyalp

  • ******
  • 14138
Re: Implementing scripts in C
« Reply #6 on: 23 / July / 2008, 00:05:33 »
...i also think we need "real" (and unlimited) parameter identifiers, it's a plague with the one-letter params on large scripts...
One obvious way to do that is to expose UI stuff through lua itself, instead of having a special pre-parser to pull out the options out of the script. This requires some re-organizing, but the payoff could be significant. I've been toying a bit with ideas of how to do this, but I need to spend more time with the code.

Note that in lua, you can could map the global one-letter options into friendly names in various ways, but having type and range control of the options would make the ui a lot easier to use and understand.

IMO, adding more power to the scripting system (and including a standard script library) is probably preferable to putting every little feature in the C code. The end user shouldn't need to know or care what is script and what is compiled code.

The elf project attacks another angle on this, but IMO this would compliment an integrated script system rather than replacing it.
Don't forget what the H stands for.

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #7 on: 23 / July / 2008, 06:51:49 »
Uhm, when you say "expose UI stuff though Lua itself", you mean that it should be the script's job to draw menus etc.?

I'm not sure I'm fond of the thought. I mean, it would be nice if you could invoke a menu or window from scripts, but I don't mind the pre-parsing of parameters at all; it allows writing quick and easy scripts without worrying too much about interface details, and since it's scripts we're talking about, that cannot be a bad thing.

One-letter variables are a plague indeed, but surely we could get rid of that limitation without changing the whole approach?

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Implementing scripts in C
« Reply #8 on: 23 / July / 2008, 08:05:48 »
I, on the other hand, would like to see the whole menu system to be Lua driven. The CHDK "core" ("critical" stuff) would be in C, and the "non-critical", dynamically (un)loadable stuff would be extensions written with e.g. Lua.

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #9 on: 23 / July / 2008, 08:33:15 »
That would be OK with me, as long as the "user written" scripts can still just have an easily written list of parameters at the top.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal