Scripts ported to lua - General Discussion and Assistance - CHDK Forum

Scripts ported to lua

  • 8 Replies
  • 2737 Views
*

Offline ultimA

  • ***
  • 137
Scripts ported to lua
« on: 25 / December / 2011, 09:28:57 »
Advertisements
I've had these ports ready for the past 6 months or so, I'll finally post them for everyone's sake too. I'm not sure if you'll make use of this, but it cannot hurt for me to try.

In my oppinion there is no need for two scripting languages, so I've ported the most usefull (IMHO, MD, intervalo etc.) and the basic util/teat scirpts all to lua. They are all tested on the SX20 and will work, except for 1 or 2 that call get_display_mode. That call needs to be replaced with a direct call to get_prop(PROPCASE_DISPLAY_MODE) and it'll be fine (I have custom-patcehd sources where the scripts work as-is).



Re: Scripts ported to lua
« Reply #1 on: 25 / December / 2011, 11:27:03 »
My opinion is the same, we could leave uBASIC and start Lua-only. I see no advantages to keep uBASIC in CHDK. I know, that this gives the user more freedom, but causes many problems and confusions too. Especially since Lua has many new commands that have been not ported to uBASIC (and probably they'll never have).
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline msl

  • *****
  • 1266
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Scripts ported to lua
« Reply #2 on: 25 / December / 2011, 12:32:45 »
My personal opinion is the same, but ...

The most CHDK users are photographers and not programmers. Maybe they know something BASIC from old times (e.g. Atari, Commedore). That helps to write a small script like time lapse. Therefore we need uBasic.

In German CHDK forum we have a big uBasic script collection,which are used very often.

Intensive CHDK users can compile their own version without uBasic. With the CHDK shell we have all options.

Lua is a powerful tool. Because you need more programming experience.

msl
CHDK-DE:  CHDK-DE links

Re: Scripts ported to lua
« Reply #3 on: 25 / December / 2011, 13:51:40 »
The most CHDK users are photographers and not programmers. Maybe they know something BASIC from old times (e.g. Atari, Commedore). That helps to write a small script like time lapse. Therefore we need uBasic.
Agreed.  To me, this fits into the category of "If its not broken,  don't fix it".


Ported :   A1200    SD940   G10    Powershot N    G16


*

Online reyalp

  • ******
  • 12370
Re: Scripts ported to lua
« Reply #4 on: 25 / December / 2011, 15:27:45 »
The most CHDK users are photographers and not programmers. Maybe they know something BASIC from old times (e.g. Atari, Commedore). That helps to write a small script like time lapse. Therefore we need uBasic.
I disagree with this a bit. If you write the kind of simple script these users would write in ubasic in lua, it's almost the same. Really the only difference for a trivial script is you have to remember to use () on function calls. ubasic is different enough from other dialects of BASIC that they still need to learn some specifics.

I suspect the popularity of ubasic is historical, it shows up in more of the wiki examples etc.

E.g waterwingz two intervalometers scripts:
Code: [Select]
do
    s = get_tick_count
shoot
    sleep a*1000 - (get_tick_count - s)
until ( 0 )
vs
Code: [Select]
repeat
    start = get_tick_count()
shoot()
    sleep(a*1000 - (get_tick_count() - start))
until ( false )
Is the first one really simpler / easier for a non-programmer to understand ?

Of course, you can write much more complicated scripts in lua, but you don't have to.

That said, I'm in no hurry to remove ubasic. It would be worth considering if we were doing a ground up re-write of the scripting stuff, but I don't see that any time soon :)

One thing that would be useful would be to make a more standardized script interface, so we don't have to have the if lua/if ubasic stuff scattered around.
Don't forget what the H stands for.

Re: Scripts ported to lua
« Reply #5 on: 25 / December / 2011, 15:43:49 »
Maybe it is too fast to removing uBasic, but we can at least try to write most of the documentation examples in Lua and port most important scripts to Lua (as ultimA started). Maybe uBasic will die by itself :o

Lua has this specific advantage, that user can simply add some commands by adding module with no or only minor changes in source...

Also - I saw that Lua is sometimes simpler than uBasic - for me this:

Code: [Select]
x = command("something")

is more logical than this:

Code: [Select]
command x "something"

But I agree - it would be bad idea to remove uBasic now... Maybe around CHDK 2.0 :D
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: Scripts ported to lua
« Reply #6 on: 25 / December / 2011, 15:47:04 »
FYI .. despite my defending uBASIC,  I have no intention of using it now or in the future.  The advantages of Lua are clear.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Scripts ported to lua
« Reply #7 on: 25 / December / 2011, 18:21:51 »
I'm still quite new to CHDK and scripting (not to programming though, as I do have quite a vast knowledge in C# and Java), but the only reason why I had chosen uBasic when I needed to write my first script was that I was finding more examples of scripts written in uBasic than in LUA. Now that I've become more familiar with how scripts work and know the possibilities that LUA offers, I'm sure that my next script will be written in LUA.

Personally, I think that the only reason why members think that LUA is more difficult is because LUA scripts are usually used for more advanced stuff.


*

Offline ultimA

  • ***
  • 137
Re: Scripts ported to lua
« Reply #8 on: 02 / January / 2012, 12:36:51 »
I wasn't proposing to remove uBasic now in an instant. Most examples and most of the usefull scripts right now are in uBasic after all, so sure as hell anyone who looks at existing examples to start his own script will probably use uBasic. Before we remove uBasic, we must make sure that we have equivalent scripts and documentation in lua. Which is why I published my ports above. I know, it is a small step. But a step.

 

Related Topics