Pages: [1] 2 3 4 Next   Go Down
  Print  
Author Topic: Lua Scripting Integration  (Read 4580 times)
0 Members and 1 Guest are viewing this topic.
Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« on: 27 / April / 2008, 10:43:03 »

Hi,

I am in the process in finishing Lua integration in CHDK. See Lua Scripting

Now I would like to contribute my work back to CHDK. CHDK more than doubled the usefulness of my camera. Thanks to all who made this possible!
My plan is to to do the same to CHDK. This requires that my work will be accepted in the CHDK community. Is it the case?

My personal opinion doesn't matter much, I think. But I find it VERY convenient to script in Lua than in uBASIC. Everyone will see/feel the difference once he tries Lua.   Smiley

So, how should I proceed?

What I don't want is another "Velo's Builds" entry in downloads. I think there are already far to many forks of CHDK.

My current plan is to ditch uBASIC at the same time. Converting uBASIC scripts to Lua is not hard. Perhaps even a Lua Script converting uBASIC to Lua on the fly should be possible.

Comments? Opinions?

Logged
fudgey
Global Moderator
Hero Member
*****

Karma: +64/-1
Offline Offline

Posts: 699

a570is


« Reply #1 on: 27 / April / 2008, 11:06:43 »

Ditching ubasic may not be a very good idea, at least without a long transition period. Users have their own scripts and forcing them to port them to use a current build may not be desirable.

Would it be hard to support for both lua and ubasic? Maybe require lua scripts to be easily identifiable by CHDK (like start with #!lua) and fall back to ubasic if it's not a lua script.
Logged
Jucifer
Global Moderator
Full Member
*****

Karma: +41/-0
Offline Offline

Posts: 221


[A710IS]


« Reply #2 on: 27 / April / 2008, 12:04:26 »

Once you publish your lua-patch, I'll at least try it. (Probably I'll end up adding it to my build.) :]
Logged

fingalo
Developers
Jr. Member
****

Karma: +23/-0
Offline Offline

Posts: 91


« Reply #3 on: 27 / April / 2008, 12:08:12 »

One comment, the UBASIC is a very simple scripting langage for non programmers also. LUA woud probably require a bit more programming experience.
But we have to evaluate it  in practice, not by opinion!
Great job Velo! I really would like to test it!
Logged
fe50
Hero Member
*****

Karma: +50/-1
Online Online

Posts: 598


IXUS 50, IXUS 860is


« Reply #4 on: 27 / April / 2008, 13:28:04 »

Sounds good to me, I'm looking forward to test LUA scripting !  Cool
My opinion: an optional second scripting language can enhance CHDK, anybody can decide to use uBasic or LUA. Perhaps it could cause some confusion with 2 languages...
Logged

Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« Reply #5 on: 27 / April / 2008, 21:15:54 »

Here is the first version of the patch (its against trunk Rev 388)
zSHARE - chdk-lua.patch.zip

I bound all functions that where available in uBASIC to Lua, except md_detect_motion. It is implemented in some special way I didn't bother to analyse. But if someone beats me to it...

I actually only tested shoot/sleep/get_prop/press/release/click because that are the only functions I need in my scripts. But the other ones are mostly very simple and should work out-of-the-box.
I could use some help in testing all functions. For half of them I don't even know what they are supposted to do.

Note that some function have now boolean parameters or results. This includes is_key,set_autostart,get_autostart,usb_power. Please inform me if some other functions should accept or return booleans instead of numbers.

What is still missing are parameters. I concentrated on providing all functions first.
I think I'll get to parameters in the next 2 or 3 days. Don't have much time weekdays.

With the patch it should be possible to run both Lua und Basic scripts. If the script file ends with .lua or .LUA it will be run as Lua script.

A new thing that some will experience is that you can now hang the camera with an improper script. Lua scripts are run until you interrupt them with shoot/sleep/press/release/click or wait_click. If you wait for an event make sure to sleep at least once in your loop.

Errors will be shown in the script console window. Sometimes this window disappears very fast after the script stops. Don't know what to do about it.

Have fun and report back how its working out!

Logged
jonnythe
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 93


« Reply #6 on: 28 / April / 2008, 00:55:25 »

I only know a bit of the Lua language. But can you tell me if external module loading is possible or planned for this? I think that would be one of the most useful features over uBasic. Having a function library of timers, delays, AV settings tables etc on the card that can be reused in the main scripts.
Logged
Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« Reply #7 on: 28 / April / 2008, 07:38:20 »

I haven't planed it in the first release. But it shouldn't be to hard to add this functionality.

When Lua is accepted I plan more features like droping the 8 kb script limit or the just described module support.
Logged
jonnythe
Jr. Member
**

Karma: +6/-0
Offline Offline

Posts: 93


« Reply #8 on: 28 / April / 2008, 09:00:12 »

I haven't planed it in the first release. But it shouldn't be to hard to add this functionality.

When Lua is accepted I plan more features like droping the 8 kb script limit or the just described module support.

No it shouldn't be hard at all. As for Lua being accepted, I don't know why not. Most of the people new to CHDK are new to Basic as well. Lua is a very clean language and there shouldn't be any problems. Geez, it should even be simple to write a uBasic wrapper to Lua modules if the need be. I'm all for it. I tried a Pawn implementation but I'm not smart enough. But Lua is powerful and if this takes off it would be possible to try many things out that would otherwise have to be done by modifying the CHDK code itself. Congrats, Velo. Good job.
Logged
Jucifer
Global Moderator
Full Member
*****

Karma: +41/-0
Offline Offline

Posts: 221


[A710IS]


« Reply #9 on: 28 / April / 2008, 13:14:33 »

tried the patch

the good:
didn't break ubasic

the bad:
couldn't get lua working :/


the ugly:
had to increase memisosize
patching /makefile.inc (and /platform/makefile_sub.inc) causes an error in win when compiling:
"../../../../tools/finsig.o: file not recognized: File format not recognized"


trying to patiently wait for new patches :]
« Last Edit: 28 / April / 2008, 19:28:44 by Jucifer » Logged

Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« Reply #10 on: 28 / April / 2008, 17:51:35 »

Hm. What is the output of 'uname -s' on MinGW?
You can revert both files if you are not building on Darwin (Mac), like I do.

For a simple Lua script you can try:

Code:
for i = 1,10 do
  print( "Picture "..i )
  shoot()
  sleep( 2000 )
end

Save it as test.lua in the scripts folder an run it.

Logged
Jucifer
Global Moderator
Full Member
*****

Karma: +41/-0
Offline Offline

Posts: 221


[A710IS]


« Reply #11 on: 28 / April / 2008, 19:28:17 »

Sorry, my bad. Doesn't need "end" at the end of the script, that prevented my hello-script from working... :]
Logged

Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« Reply #12 on: 01 / May / 2008, 09:59:37 »

I finally got around implementing script parameters.
@Jucifer: The build problems on MinGW should be fixed too.

zSHARE - chdk-lua-2.patch.zip

To be compatible with basic, parameters have the same restrictions as in basic. This means parameters must have names of a,b,c,... or z. But you still can use longer variable names in your script.

Like so:
Code:
--[[
@title Intervalometer
@param a Interval (Seconds)
@default a 2
@param b Interval (10th Seconds)
@default b 0
]]

timeout = a*1000+b*100
nr = 0

while true do
  nr = nr + 1
  print( "Picture "..nr )
  shoot()
  sleep( timeout )
end

Note that parameters must be enclosed in a Lua-comment block to be recognized by the params parser but ignored from Lua.

Lacking more feedback I haven't changed anything else. Please try my patch and report back. Critics and comments are always welcome.

Logged
Jucifer
Global Moderator
Full Member
*****

Karma: +41/-0
Offline Offline

Posts: 221


[A710IS]


« Reply #13 on: 02 / May / 2008, 09:06:10 »

I'm trying to convert an existing script, and now have a major problem with press(). The code I'm trying to get working is basically

Code:
C=get_exp_count
press "shoot_half"
press "shoot_full"
do
D=get_exp_count
until (D-C)>=j
release "shoot_full"

so it could convert to something like

Code:
count_initial = get_exp_count()
press( "shoot_half" )
press( "shoot_full" )
repeat
until ( get_exp_count() - count_initial ) >= count_target
release( "shoot_full" )
.

Here's the problem:
uBASIC version does what it's supposed to: presses shoot_half, (actually goes to loop already), presses shoot_full when shoot_half completed...
Lua version presses shoot_half and goes to loop, but shoot_full never gets pressed.
Why?
I have no idea. Could this have something to do with stack manipulation?
Logged

Velo
Newbie
*

Karma: +8/-0
Offline Offline

Posts: 30


« Reply #14 on: 02 / May / 2008, 12:07:31 »

Hi Jucifer

Code:
repeat
until ( get_exp_count() - count_initial ) >= count_target

Could be that you enter a loop without sleep(). Try

Code:
repeat
  sleep(10)
until ( get_exp_count() - count_initial ) >= count_target

I made this bug myself two or three times. I'll have to think of a solution than works without sleep.
Logged
Pages: [1] 2 3 4 Next   Go Up
  Print  
 
Jump to: