Implementing scripts in C - page 2 - Feature Requests - CHDK Forum  

Implementing scripts in C

  • 24 Replies
  • 6592 Views
*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Implementing scripts in C
« Reply #10 on: 23 / July / 2008, 13:30:09 »
Advertisements
Yep, being able to draw menus and other user interaction other than our current console would be great. I agree with LjL about the parameter thing, though: it's nice to have an interface that's the same for all scripts as it eases writing the scripts and it makes using the scripts easier as they tend to work with the same buttons.

That said, there are uBasic scripts which have an user interface already... they often have a keymap help text in the console. So the need for script run-time menus is clearly already there.

As for drawing all CHDK menus with Lua... I have no opinion as long as things don't slow down because of it. And I'm sure nobody likes single letter variables. ;)

I don't think we should "ever" remove uBasic, I believe it's a lot easier for a complete newbie to learn to read and write compared to Lua.

*

Offline Velo

  • *
  • 30
Re: Implementing scripts in C
« Reply #11 on: 23 / July / 2008, 16:20:53 »
I don't think we should "ever" remove uBasic, I believe it's a lot easier for a complete newbie to learn to read and write compared to Lua.

Can you please elaborate on this? Simple uBasic scripts converted to Lua are in my eyes nearly identical. Which syntax do you have in mind that is easier for newbies to write/grasp?

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Implementing scripts in C
« Reply #12 on: 23 / July / 2008, 17:24:25 »
Can you please elaborate on this? Simple uBasic scripts converted to Lua are in my eyes nearly identical. Which syntax do you have in mind that is easier for newbies to write/grasp?

I may be wrong, but, I'd think a typical Lua script isn't really something converted from BASIC. Since Lua is way more powerful, a typical Lua script will resemble C more than BASIC in that it has paranthesis, functions, possibly even library functions and it utilizes more loops instead of GOTOs etc.

My bottom line (and I'm not trying to start a war here) is that if Lua is a programming language, uBasic is more like a shopping list. :D

Don't get me wrong, I have nothing against Lua and I wish it was in trunk and that md_detect_motion would fully work on Lua. After a learning curve, I'm sure Lua scripts are way easier to write and maintain.

I just think that there's no reason to remove uBasic just because we have a superior alternative, because the alternative may not be superior to everyone. I believe the two can happily coexist until an elf edition comes along, at which point there's just no need to worry about it any longer.

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #13 on: 23 / July / 2008, 19:23:38 »
I've nothing against keeping uBASIC, but I really cannot stop screaming when I see goto's advocated for any reason... eek. You're seriously saying it's easier for the "casual user" to think in assembly terms - "if this happen, go back to the instruction location N", rather than "repeat the following ten times, stop if X happens"?


*

Offline reyalp

  • ******
  • 12796
Re: Implementing scripts in C
« Reply #14 on: 24 / July / 2008, 00:29:36 »
Uhm, when you say "expose UI stuff though Lua itself", you mean that it should be the script's job to draw menus etc.?
What I had in mind was using C to actually draw them, but a lua table would describe the options, hold the values, and potentially contain code to handle more complex things like options with ranges or options that depend on other options. Properly implemented, it could still be as simple as the current system (i.e. defaulting to a handful of generic options, or a few simple lines in the script file that fill out a default menu)

The change in approach is that part of the script has to run when the user sets the options.

One thing lua makes very convenient is tying script and C code together in various ways.
Quote
One-letter variables are a plague indeed, but surely we could get rid of that limitation without changing the whole approach?
Sure, you could extend
Code: [Select]
@param X Number of fraks in the frobulatorto
Code: [Select]
@param NumFrobFraks Number of fraks in the frobulatorwithout much trouble. I'd probably throw the default in there somewhere too so you don't have to write each one twice ;)

If you only ever want to use scripting for the kinds of things it's used for now, that's good enough (although the menus for things like the motion detection scripts are already pretty nasty) However, with something like lua, you can potentially do a lot more, and make the interface to complex scripts easier.

I'm not sure I buy the UBASIC being easier to write argument. Lua started life as a way to write configuration files, and can still be used that way. It's up to the implementer of the host application to expose it in a way that is easy to use.

ubasic OTOH is simple because it is limited, but from what I can see is still pretty quirky and more painful to integrate with C code.

Keep in mind this is random musing from someone who only recently started exploring the CHDK code. The real proof of any idea is someone having the motivation to code it, and users deciding it was better than what came before.  ;)
Don't forget what the H stands for.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Implementing scripts in C
« Reply #15 on: 24 / July / 2008, 01:39:42 »
I've nothing against keeping uBASIC, but I really cannot stop screaming when I see goto's advocated for any reason... eek. You're seriously saying it's easier for the "casual user" to think in assembly terms - "if this happen, go back to the instruction location N", rather than "repeat the following ten times, stop if X happens"?

Oh, again, don't get me wrong... I'm not advocating gotos. They are usually bad for you and make even a small script hard to interpret unless it's just one eternal loop with one goto. But I'm seriously saying they are easier to learn (uBasic's lack of line numbers make them slightly harder to follow, but not much) than remembering to properly select and lay out a while/for/do loop syntax and trying to avoid off-by-one errors while at it.

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Implementing scripts in C
« Reply #16 on: 24 / July / 2008, 02:27:35 »
by the way, don't want to spoil anything, but i've got reliable sources telling me they beefed up ubasic heavily by introducing a select/case statement. this is gonna be good.

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #17 on: 24 / July / 2008, 06:45:10 »
Ok, so which one is easier to read and learn (both are fictional, I don't really know uBasic)?

Code: [Select]
while is_pressed(KEY_SHOOT) shoot


start: if not is_pressed(KEY_SHOOT) then goto exit
shoot
goto start
exit:


Re: Implementing scripts in C
« Reply #18 on: 24 / July / 2008, 07:06:06 »
The first one is easier to read, but the second one is intentionally convoluted and difficult when it could have been written much simpler in uBASIC. It's clear that you are trying to get rid of uBASIC by your biased example, but 99% of people who have had any exposure to programming already know some form of BASIC, uBASIC being a very simple implementation of it. I doubt anyone but a few esoteric programmers know LUA. I certainly don't. I've not even heard of it until now. And I find it very difficult to read and understand. What's with all those useless () in every command? None of LUA makes any sense.

Give it a rest.  Unless you intend to write up an extremely detailed and CHDK specific tutorial on all its applications with all of CHDK's commands with examples for all usage of every form that LUA can take. While you're at it, make another script archive with all the presently known scripts converted to LUA. That should keep you busy.





« Last Edit: 24 / July / 2008, 07:13:56 by NewbieToobie »

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: Implementing scripts in C
« Reply #19 on: 24 / July / 2008, 07:20:46 »
Quote
It's clear that you are trying to get rid of uBASIC by your biased example

If it's clear to you, I'm glad you think you can read people's minds :)

I'll say nothing further regarding your post.

 

Related Topics