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

what is your Lua script writing environment like?

  • 62 Replies
  • 18871 Views
*

Offline reyalp

  • ******
  • 11900
Re: what is your Lua script writing environment like?
« Reply #40 on: 21 / April / 2013, 16:22:14 »
Advertisements
Now I remember that problem

Here's a version of the script that runs 'require' in the correct environment, based on the one msl posted above. Bonus, you can now use --modroot to specify that path these are loaded from, e.g.

lua emu.lua test.lua --modroot=d:/chdk/trunk/CHDK

instead of having to copy all your scripts under A/

Since there seems to be some interest in this, I'm thinking about checking it in under the hostlua directory.

note the --conf option was something I planned but apparently never implemented. The idea was that it would be a local lua file that can customize the emulated environment, so for example you could set the propset, model etc without changing the main file. Also, you could override emulator functions, for example, you could make get_bv96 return a specific series of BV values to test your script.

edit:
this is now checked in, see http://trac.assembla.com/chdk/browser/trunk/tools/hostlua/emu/emu.lua for the latest version.
« Last Edit: 21 / April / 2013, 19:38:11 by reyalp »
Don't forget what the H stands for.

Re: what is your Lua script writing environment like?
« Reply #41 on: 21 / April / 2013, 19:00:07 »
Here's a version of the script that runs 'require' in the correct environment, based on the one msl posted above. Bonus, you can now use --modroot to specify that path these are loaded from, e.g.
Close .. the filespec under Linux is case sensitive so lines 443 & 445 need to have ".lua" in lower case to find the files from the CHDK distro file stored in A/

Code: [Select]
        local f=loadfile(camera_module_root..'/SCRIPTS/'..mname..'.lua')
        if not f then
                f=loadfile(camera_module_root..'/LUALIB/'..mname..'.lua')
        end
I assume there must be a more elegant way to make this case independent?

Quote
Since there seems to be some interest in this, I'm thinking about checking it in under the hostlua directory.
Seems like a good idea to me - I keep updating the camera functions to track what I'm working on and then losing it when I get a new version (not a big deal - each version gets better). 

Might make sense to put the script functions into another file and including it in emu.lua.  That way you seperate the emulator part from the actual CHDK functions.

Quote
note the --conf option was something I planned but apparently never implemented. The idea was that it would be a local lua file that can customize the emulated environment, so for example you could set the propset, model etc without changing the main file. Also, you could override emulator functions, for example, you could make get_bv96 return a specific series of BV values to test your script.
You're teasing us ...  I think that finishing things so its easy to run from Notepad++ (rudy..) or Geany (me?) might make this a lot more popular with the average CHDK user  (sort of like CHDK-Shell brought CHDK compiling to so many ...)
« Last Edit: 21 / April / 2013, 19:06:47 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 11900
Re: what is your Lua script writing environment like?
« Reply #42 on: 21 / April / 2013, 19:29:01 »
Close .. the filespec under Linux is case sensitive so lines 443 & 445 need to have ".lua" in lower case to find the files from the CHDK distro file stored in A/
Oops, I thought they were upper case in the CHDK directory. Fixed. (edit: in the trunk)
Quote
I assume there must be a more elegant way to make this case independent?
It's a little bit tricky. You'd have to list the directory and do a case insensitive comparison or something.

Quote
Might make sense to put the script functions into another file and including it in emu.lua.  That way you seperate the emulator part from the actual CHDK functions.
Yes. This is complicated by the fact that the Lua package loading code is heavily butchered in the CHDK version of Lua, and this caries over to hostlua.

See the #if 0 stuff in lua/lib/loadlib.c

While we could theoretically make some of the #if 0 into #ifdef HOST_LUA, it might be worth restoring some of this in chdk proper. I think the original reason it was butchered is because required functions like strchr were not available, but many of these have been found since.
« Last Edit: 21 / April / 2013, 19:37:09 by reyalp »
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 11900
Re: what is your Lua script writing environment like?
« Reply #43 on: 22 / April / 2013, 00:16:28 »
I've updated the trunk emu.lua in changeset 2724

This splits camera_funcs into it's own file. I also implemented the conf option.

note camaera_funcs.lua is expected to be available on the Lua path. The simplest way to get this is to run the emulator script from the emu directory, but hostlua built after r2723 should honor the LUA_PATH environment variable.

Example
../lua emu.lua test.lua --modroot=d:/chdk/trunk/CHDK --conf=a540.lua

example a540.lua conf file
Code: [Select]
local camera_funcs=require'camera_funcs'
function camera_funcs.get_buildinfo()
return {
platform="a540",
build_date="Apr  7 2013",
build_number="1.2.0",
build_time="16:03:05",
version="CHDK",
platsub="100b",
build_revision="2684",
platformid=12571,
os="vxworks",
}
end
function camera_funcs.get_propset()
    return 1
end

The whole thing is pretty quick n dirty, it could really use some proper structure...
Don't forget what the H stands for.


Re: what is your Lua script writing environment like?
« Reply #44 on: 22 / April / 2013, 02:45:06 »
Hello!

I am looking for an information about how to compile this hostlua. Since I usually don't work with compilers I have completely no idea how to even start. I suspect I need to svn-download the trunc/tools from assembla and then compile it? But how...

Is there any description somewhere on the wikia? Or if this is not the case - can anybody describe the process here? Then I could try this myself and write a simple how-to on wikia.

Thank you in advance!

System: Kubuntu 12.04. I can also use Win7 instead.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline reyalp

  • ******
  • 11900
Re: what is your Lua script writing environment like?
« Reply #45 on: 22 / April / 2013, 03:01:43 »
I am looking for an information about how to compile this hostlua. Since I usually don't work with compilers I have completely no idea how to even start. I suspect I need to svn-download the trunc/tools from assembla and then compile it? But how...
You need a complete CHDK build environment. There should be instructions for that on the wiki, though on linux it isn't entirely trivial.

On windows, CHDKShell should give you everything you need. Use the command prompt button to get a shell.

After the build environment is set up, you should be able to just
Code: [Select]
cd tools/hostlua
make
Don't forget what the H stands for.

*

Offline whim

  • ******
  • 2013
  • A495/590/620/630 ixus70/115/220/230/300/870 S95
Re: what is your Lua script writing environment like?
« Reply #46 on: 22 / April / 2013, 04:40:42 »
Quote
On windows, CHDKShell should give you everything you need. Use the command prompt button to get a shell.

After the build environment is set up, you should be able to just ...

Confirmed working on CHDK-Shell v3.44 with trunk 2724 (tested compiling only)

wim
« Last Edit: 22 / April / 2013, 04:46:02 by whim »

*

Offline msl

  • *****
  • 1261
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: what is your Lua script writing environment like?
« Reply #47 on: 22 / April / 2013, 08:00:55 »
Thanks for the hostlua & emu.lua improvements.

Our notepad++ project runs fine.  The splitting of the camera functions is not so good (for our project), but it works.

msl
CHDK-DE:  CHDK-DE links


*

Offline reyalp

  • ******
  • 11900
Re: what is your Lua script writing environment like?
« Reply #48 on: 22 / April / 2013, 12:51:02 »
The splitting of the camera functions is not so good (for our project), but it works.
What problems does it cause? Maybe we can make it better.
Don't forget what the H stands for.

Re: what is your Lua script writing environment like?
« Reply #49 on: 22 / April / 2013, 14:04:37 »
Thanks for your help, after make I got compiled *something* but I still have no idea how to use the hostlua... I mean what to run to run a script.

If there's any documentation you could give me a pointer to I would appreciate that. Mainly to avoid wasting your time with my questions:)
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics