Lets create some lua libraries - LUA Scripting - CHDK Forum supplierdeeply

Lets create some lua libraries

  • 14 Replies
  • 7911 Views
Lets create some lua libraries
« on: 07 / January / 2009, 09:25:42 »
Advertisements
I've found in the process of writing my own scripts that i'm solving some basic and universal problems. The main ones that come to mind are "delete oldest image" and "rename newest file". I'm also considering abstracting the night time-lapse script into a low light shot script.

I will certainly create the versions of the scripts that i feel would be useful to all, but i'm certain that other people are working on similar things and our efforts should be organized and combined.

Once I have the start of a small library i'll start a wiki page for it unless someone else has a better idea on how to organize this.

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Lets create some lua libraries
« Reply #1 on: 07 / January / 2009, 09:58:57 »
good idea. hopefully these then one day end up in the autobuild, so people dont have to search the wiki yet to have a nice and working chdk on their cams.

Re: Lets create some lua libraries
« Reply #2 on: 11 / January / 2009, 20:04:06 »
are the words "module" and "library" interchangeable in lua?

*

Offline reyalp

  • ******
  • 11995
Re: Lets create some lua libraries
« Reply #3 on: 11 / January / 2009, 21:03:39 »
are the words "module" and "library" interchangeable in lua?
Module has a specific meaning, relating to the lua package system. See http://www.lua.org/manual/5.1/manual.html#5.3
Don't forget what the H stands for.


Re: Lets create some lua libraries
« Reply #4 on: 11 / January / 2009, 21:12:51 »
yes, i read that but failed to make much sense of it. can you explain to me the difference between a chdk lua lib and a lua module?

*

Offline reyalp

  • ******
  • 11995
Re: Lets create some lua libraries
« Reply #5 on: 11 / January / 2009, 21:32:27 »
A CHDK lua library should probably be loaded with require, but need not be. You could load a lua script full of functions with loadfile etc if you wanted.

You could use module() in your lua modules or not as you wish, although as people write bigger and more complex scripts it's probably a good idea.

It's worth noting that some of the package loading stuff (package.path at least) is crippled in the current CHDK lua port. I intend to fix that at some point.
Don't forget what the H stands for.

Re: Lets create some lua libraries
« Reply #6 on: 01 / February / 2009, 11:24:52 »
here's the first revision of lua libs. it makes liberal use of other people's work, mainly fbonomi and fudgey. hopefully this repackaging will help other people write scripts and encourage them to share their own code.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lets create some lua libraries
« Reply #7 on: 01 / February / 2009, 12:04:36 »
Don't know if any of those date functions are really necessary since os.date works pretty well as is:

os.date("%Y/%m/%d %X")



edit: oh and I forgot to warn you before: disk.secs_to_disk_full() is broken somehow (it gives incorrect output most of the time but not always), I haven't had the time to debug it.
« Last Edit: 01 / February / 2009, 12:06:25 by fudgey »


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lets create some lua libraries
« Reply #8 on: 01 / February / 2009, 12:27:53 »
this was my revised f-date.lua btw:

--[[
  Functions that return Date/Time strings for use in CHDK Lua scripts.
 
  Author: 2008/10/27 fudgey
  Licence: GPL
--]]

-- Return a timestamp string (hh:mm:ss).
-- If called without parameters, uses current time from camera clock.
-- If a parameter (number) is passed, it is used (seconds after midnight).
function timestamp(t)
  if t==nil then
    return os.date("%X")
  else
    return os.date("%X",t)
  end
end

-- Returns formatted date string from camera clock.
-- Output format example: 2008/09/25
function datestamp()
  return os.date("%Y/%m/%d")
end

-- Returns formatted date + time string from camera clock.
-- Output format example: 2008/09/25 23:05:59
function datetimestamp()
  return os.date("%Y/%m/%d %X")
end

Re: Lets create some lua libraries
« Reply #9 on: 01 / February / 2009, 12:39:37 »
updated, thanks!

 

Related Topics