how to organize library functions? - LUA Scripting - CHDK Forum

how to organize library functions?

  • 5 Replies
  • 4256 Views
how to organize library functions?
« on: 27 / January / 2009, 21:19:37 »
Advertisements
i'm trying to figure out the best way to organize library functions. i would like to have one object per lib, named the same as the lib. for instance, date functions could be accessed through the xdate object (table?). x - to signify that its a lua extension. this would result in the f-date library functions being reorganized as such -

xdate.format_nn
xdate.timestamp
xdate.datestamp
xdate.datetimestamp

any ideas?

Re: how to organize library functions?
« Reply #1 on: 27 / January / 2009, 23:05:56 »
got it

xdate = {}
function xdate.format_nn(n)
  local r=tostring(n)
  if n<10 then
    r= "0" .. n
  end
  return r
end

*

Offline reyalp

  • ******
  • 14128
Re: how to organize library functions?
« Reply #2 on: 28 / January / 2009, 01:49:57 »
http://www.lua.org/manual/5.1/manual.html#5.3 describes the standard way to do this.
Don't forget what the H stands for.

Re: how to organize library functions?
« Reply #3 on: 28 / January / 2009, 10:33:30 »
ah yes, the module functions.

the manual doesn't help me make any sense of it but i've found a page that appears to help quite a bit.

http://www.chipmunkav.com/help/LuaModules.htm

i'll attempt to module-ize and report back.

Re: how to organize library functions?
« Reply #4 on: 28 / January / 2009, 20:46:12 »
anyone have success using the module function? i get an error reporting that i'm attempting to use a nil function.

*

Offline reyalp

  • ******
  • 14128
Re: how to organize library functions?
« Reply #5 on: 28 / January / 2009, 22:25:48 »
It's possible that it's currently broken in CHDK lua, I haven't actually tested it.
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal