We have moved at community.getvera.com

Author Topic: making a 'global' library with functions and variables.  (Read 1627 times)

Offline vincenthimpe

  • Sr. Newbie
  • *
  • Posts: 28
  • Karma: +0/-1
making a 'global' library with functions and variables.
« on: July 12, 2011, 09:41:40 pm »
Here is what i want to do. I want to create a library with often used functions that i can call from luup scripts.
These functions need to be global.

For example :

porchlight =27  ' z-wave device 27
kitchenlight =15 ' z-wave device 15

function TurnOn (device)
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device)
end
function TurnOff (device)
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device)
end

so i can write in the luup scripts :

TurnOn (porchlight)
TurnOff (kitchenlight)

How do i create such a file , and how do i get it onto Vera ? And how do i edit this file ?
I know NOTHING about linux so if command lines . ssh tools etc are involved i need STEP BY STEP instructions.
I have a whole set of 'basic' functions i want to create.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: making a 'global' library with functions and variables.
« Reply #1 on: July 13, 2011, 01:09:16 am »
Put it all into a .lua file, and upload via the Browser using the standard options under MiOS Developer.

When you want to use it, lookup the Lua construct require(...)

For more advanced versions of this, you'll want to lookup the Lua-users Tutorial on Tables and Metatables, but require is the easiest way to get it going.


Offline vincenthimpe

  • Sr. Newbie
  • *
  • Posts: 28
  • Karma: +0/-1
Re: making a 'global' library with functions and variables.
« Reply #2 on: July 13, 2011, 12:47:25 pm »
Excellent. That is a good start

Offline S-F

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +62/-12
  • Clueless N00b
Re: making a 'global' library with functions and variables.
« Reply #3 on: July 15, 2011, 06:41:21 pm »
I eagerly look forward to seeing how this progresses.
My forum account was apparently hacked by a leprechaun. And he's drunk all of the time. If a post of mine seems a little off kilter, it's probably because he made it.