what is your Lua script writing environment like? - LUA Scripting - CHDK Forum

what is your Lua script writing environment like?

  • 62 Replies
  • 33200 Views
what is your Lua script writing environment like?
« on: 10 / January / 2009, 08:55:26 »
Advertisements
I've done quite a bit of lua script writing - at least enough to worry about how many insertions an SD card is good for. It would be a great boost to my productivity if i could test my scripts without having to write them to an SD card, put the card into the camera and then run them.

What is your Lua script writing environment like?

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: what is your Lua script writing environment like?
« Reply #1 on: 10 / January / 2009, 09:13:24 »
I don't do much, but see the pc directory in the SunsetF15 zip package. The script runs on PC, I always tried major new stuff on PC before camera when I was working on the script modifications. Reyalp recently added a CHDK modified PC Lua version to CHDK svn to fix some annoyances (like int on camera vs float on PC), I haven't tried it yet but it did compile fine on Ubuntu.

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: what is your Lua script writing environment like?
« Reply #2 on: 10 / January / 2009, 12:48:51 »
I have a dummy.lua file that defines dummy versions of the camera-only functions
Code: [Select]
function get_tick_count()
 return os.time()*1000
end

function get_day_seconds()
 return os.time()
end

function get_time(s)
 return 0
end


function get_usb_power(x,y)
 return 0
end

function set_prop(x,y)
 
end

function get_prop(x,y)
 return 0
end

function sleep(n)
 x=n
end

function print_screen(n)
 x=n
end

function press(s)
 x=s
end

function shoot(s)
 x=s
end

function shot_histo_enable(s)
 x=s
end

function  get_histo_range(n1,n2)
 return 100
end

function set_tv96_direct(n)
 x=n
end

function set_bv96(n)
 x=n
end

function set_sv96(n)
 x=n
end


function get_bv96()
 return 0
end

function get_av96()
 return 0
end

function press(n)
 x=n
end

function release(n)
 x=n
end

function shutdown()
end

Then, I divide my programs in modules: some modules can be ran on PC and camera, others can't

Of the ones that can't, I do a dummy version that runs on the PC, resulting with two fles: module.lua (real file) module_dummy.lua (dummy file for PC)

Finally, in the main program, I have something like:

Code: [Select]
-- determine if we are on the camera or if we are just debugging on the PC
if (type(shoot)=="function") then
 -- shoot() is defined, we are on a camera
 -- require the real modules
 require("module")
else
 -- shoot() is undefined, we are on a PC
 -- require the basic dummy functions
 require("dummy")

 -- and require the dummy version of the modules
 require("module_dummy")


end
-- some modules can be ran on PC and camera
require("othermodule")

this results in a program program that can be ran (mainly for syntax checking9 on PC and camera)
« Last Edit: 10 / January / 2009, 12:51:49 by fbonomi »

*

Online reyalp

  • ******
  • 14081
Re: what is your Lua script writing environment like?
« Reply #3 on: 10 / January / 2009, 18:20:03 »
You might want to consider using hostlua: changelog of trunk including comments / devtalk

As I noted there, I'm working on a more sophisticated emulation environment based on this, which will eventually be added to svn.

Attached is my very very preliminary "emulator".

Currently, it parses the @options, and also allows you to override them using -a=X etc on the command line. Unlike fbonomis approach, it doesn't require a dummy module in the script being tested.

If you make a file tree starting with A/ in the directory where the test is run, chdk file operations will treat this as the camera filesystem (because the host OS will treat A/ as a relative path). llibtest.lua runs, although there are some errors related to using peek to inspect file pointers.  On windows, remove() also fails to remove a directory.

The "conf script" stuff will eventually let you load an additional script that customizes the test environment, so for example you could over-ride the key press functions to return a specific sequence of keys, or set a particular propcase to return a sequence of values, or modify the shoot() function so it copies in a CRW or jpeg.

As noted above, this is a very early work in progress, more of a sketch of what I plan to do than anything else.
Don't forget what the H stands for.


Re: what is your Lua script writing environment like?
« Reply #4 on: 10 / January / 2009, 20:00:46 »
To prevent simple syntax errors:

1) I strongly recommend you install and use the SciTE editor - it has syntax highlighting and is a fantastic fast and reliable script editor for both Windows and Linux - with good windows integration. Get it from http://www.scintilla.org/SciTEDownload.html - if using windows get the "windows installer" download contributed by Bruce Dodson; if Linux use your preferred package manager. I have converted my non-programmer work mates over to using SciTE for editing any types of script files and they like it too.

Install Lua as well. You can the "run" the scripts by using the compile menu option (F5) - If you get a syntax error then double click on it to be taken to the relevant line. Untick the Output menu option (F8) to hide the error output window.

F5 runs the lua script which does a syntax check - however you will get an error when the script tries to call the inbuilt CHDK functions. fbonomi's dummy.lua file above looks like a great idea!

PS: My *only* gripe with SciTE is control-R reverts the current file to an unedited state - I have to take care not to hit that by mistake. Apart from that it is a damn fine editor!

*

Offline whim

  • ******
  • 2046
  • A495/590/620/630 ixus70/115/220/230/300/870 S95
Re: what is your Lua script writing environment like?
« Reply #5 on: 10 / January / 2009, 20:43:06 »
@robocat

Quote
PS: My *only* gripe with SciTE is control-R reverts the current file to an unedited state - I have to take care not to hit that by mistake. Apart from that it is a damn fine editor!

In case Windows is your OS, try Notepad++ : also Scintilla-based, but Ctrl-R just pops up the replace dialog.
I know SciTE too, BTW -- it's the AutoIt (http://www.autoitscript.com/autoit3/) default editor (which i use to write CardTricks & CHDK-Shell)

cheers,

wim

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: what is your Lua script writing environment like?
« Reply #6 on: 11 / January / 2009, 02:48:50 »
As I noted there, I'm working on a more sophisticated emulation environment based on this, which will eventually be added to svn.

reyalp, I completely missed that.
very good job!

Re: what is your Lua script writing environment like?
« Reply #7 on: 11 / January / 2009, 17:30:19 »
i've started a wiki page for this info

http://chdk.wikia.com/wiki/LUA_Dev_Environment

---

Also, i'm very happy with BBEdit as my editor.
« Last Edit: 11 / January / 2009, 17:37:16 by mattkime »


Re: what is your Lua script writing environment like?
« Reply #8 on: 11 / January / 2009, 18:49:06 »
thanks reyalp, i'm making use of your script.

Re: what is your Lua script writing environment like?
« Reply #9 on: 11 / January / 2009, 21:08:26 »
reyalp - some initial feedback -

i've attempted to run my modified copy of sunsetF15.lua.  unfortunately this requires reading directory contents which makes use of chdk additions to the lua standard. the emu.lua script will need copies of these additions. i'm starting work on implementing os.listdir. unfortunately it seems that lua is ideologically opposed to adding this feature in any regular manner.

another goal is to make available the modules in CHDK/LUALIB

 

Related Topics