Compressing Lua scripts to use less memory - page 3 - LUA Scripting - CHDK Forum

Compressing Lua scripts to use less memory

  • 28 Replies
  • 18674 Views
Re: Compressing Lua scripts to use less memory
« Reply #20 on: 19 / December / 2014, 20:06:36 »
Advertisements
Since changing the language from the default needs an existing language file anyway, moving that script into a file won't make the user experience any worse. So, IMO it's a good idea.
Good point.  CHDK is a very long time past the day when you could simply put a PS.FI2 file on your SD card and expect full functionality.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Compressing Lua scripts to use less memory
« Reply #21 on: 19 / December / 2014, 20:34:13 »
The next complication is the 'lua_script_default' script hard wired into the CHDK source, if no script file is selected or it cant be loaded it uses this built in script. This script allows language selection from English, German and Russian.

Having a built in script makes using a loader for Lua scripts more difficult. It's probably doable; but the code is going to get messy.

I'm thinking to do away with any built in default script altogether - the current built in code could be moved to an actual script file and set as the default filename if the user has not selected one. This will also save a bit of memory.

Any thoughts?
Since changing the language from the default needs an existing language file anyway, moving that script into a file won't make the user experience any worse. So, IMO it's a good idea.

I misread what the script does - it checks the CHDK language selected against the Canon language selection and if they are different it updates the CHDK language to match what the user selected in the camera.

Only works for English, German and Russian.

As it turns out the script currently does not work in all cases (due to a bug in the conf_setValue function).

I definitely think moving it to a file will not reduce functionality (if the file is the default script file). If this script file is missing then there are probably other problems the user needs to deal with.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: Compressing Lua scripts to use less memory
« Reply #22 on: 19 / December / 2014, 20:57:39 »
it checks the CHDK language selected against the Canon language selection and if they are different it updates the CHDK language to match what the user selected in the camera.
If the default CHDK configuration was to run this once the first time <ALT> was entered, I can see how this might be a good thing.  But that's not how it works.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Compressing Lua scripts to use less memory
« Reply #23 on: 20 / December / 2014, 04:08:29 »
Attached patch implements running Lua scripts using a simple loader (except for PTP where they are still run from memory).

I may be calculating something wrong; but this appears to reduce runtime memory by 43K for the llibtst.lua script (13K file) and 47K for the EDI.lua file (22K file).

Other changes:
- script parameters are limited to the first 4K of the script file (only loads and parses this much of the file)
- moved the built in default script to CHDK/SCRIPTS/default.lua, this will be loaded if no other script selected
- if script file can't be parsed for parameters then 'NO SCRIPT' is shown and script will not run (script does not have to have any parameters; but first 4K must be loadable and file must exist)
- added menu option to reset script to default
- merged the 'Parameter set' and 'Save params' menu options into a single line (on/off + param set number together).

I'd like to get more testing, especially with large scripts, and PTP, before putting this into 1.4.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)


*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Compressing Lua scripts to use less memory
« Reply #24 on: 20 / December / 2014, 05:17:30 »
I'd like to get more testing, especially with large scripts
The patch seems to be fine.

The script twilive, ~63 kb, runs without memory problems on the SX220. This camera has a small free memory space, ca. 400k. Without this patch or a Lua loader I get a memory error.

msl
CHDK-DE:  CHDK-DE links

Re: Compressing Lua scripts to use less memory
« Reply #25 on: 20 / December / 2014, 10:57:11 »
CHDKplus.lua (40K) and KAP_UAV.lua (30K) both work fine on my A1200 ( 480K max free memory).   They also run fine on my old VXWorks A560.

It was also a really pleasant surprise just how good the filenames look with upper & lower case letters in the CHDK file browser !
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Compressing Lua scripts to use less memory
« Reply #26 on: 20 / December / 2014, 17:55:05 »
The changes for running Lua scripts via the simple loader are now in 1.4 revision 3833.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline reyalp

  • ******
  • 14079
Re: Compressing Lua scripts to use less memory
« Reply #27 on: 20 / December / 2014, 18:26:32 »
Quote
This would also need to re-load the script file from the SD card every time the script is run, would this be a significant performance hit?
It would probably be worth checking, but I suspect it's not a big deal.
On D10 using a class 2 SD card, "require"ing a 2kb file takes about 20ms. This doesn't seem significant to me.
Don't forget what the H stands for.


Re: Compressing Lua scripts to use less memory
« Reply #28 on: 20 / December / 2014, 18:28:35 »
On D10 using a class 2 SD card, "require"ing a 2kb file takes about 20ms. This doesn't seem significant to me.
Might actually make the "run script at startup" function work more reliably.   :blink:
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics