background preloader

LUA

Facebook Twitter

How to create my own common set of functions? You can also put your common stuff into a ".lua" file, like "shared.lua", and upload it via the standard MiOS developers UI, as you would with Plugin files. Then, in your code, you place the following construct at the top: require("shared.lua") and it'll load that library in, and it's functions will become available for you to use. This will work "as-is" on the newest MiOS releases On older MiOS releases, the "right" directories weren't setup, so uploaded .lua wouldn't be seen. In this case, you'll likely have to add the explicit path, something along the lines of: require("/etc/cmh-ludl/shared.lua") as the "/etc/cmh-ludl/" directory is where the UI uploads files to on the Vera box. 01 xx/xx/11 xx:xx:xx.133 LuaInterface::StartEngine failed run: 0 [string "x = require("test1")"]:1: module 'test1' not found: no field package.preload['test1'] no file '.

For reference, the details of this are here: The Programming Language Lua. Lua Unofficial FAQ (uFAQ) Luup Lua extensions - MiOS. In addition to the [Lua] commands described in the [Lua reference manual], you can also reference in your Lua code variables and functions from modules which the Luup engine provides as follows: Module: luup These are general purpose functions and variables. Call them by using the luup. module, such as: luup.log('Now running version: ' .. luup.version) variable: device The ID of this device instance, if it's running as part of a device variable: version, version_branch, version_major, version_minor version contains the version of the luup engine, such as "1.0.843", as a string.

If( version_branch ~= 1 or version_major ~= 0 or version_minor < 843 ) then luup.log("I need version 1.0.843 minimum to run") return falseend variable: longitude Contains the longitude as a number, as found on the location tab in the setup UI. variable: latitude Contains the latitude as a number, as found on the location tab in the setup UI. variable: timezone variable: city variable: devices The members are: variable: rooms. Luup Variables. The "Variables" for a device tell you it's current state, such as if it's on or off, what temperature it has, and so on. Variables are given a name and a service ID, which is defined by the UPnP forum. You can use this service ID/variable name pair to get the state of a device in the Luup engine by using the function luup.variable_get, as documented in Luup_Lua_extensions.

You can also see the current value of a device's variables by going into Vera's setup page, click 'Devices', click + next to the device, then click 'Advanced'. The name of every variable for the device is shown along with the current value, and if you move your mouse over the variable name, you will the corresponding service ID in a popup window. Device category Device Category 3, UPnP device id: urn:schemas-upnp-org:device:BinaryLight:1 Variables Examples Getting whether the Switch/Light is on or off Request that the Switch be turned on.

Device category 2, UPnP device id: urn:schemas-upnp-org:device:DimmableLight:1. Luup Scenes Events. Adding Lua code to scenes and events You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning "do something only if some condition is met", such as attaching a condition to your "Come Home" scene so it is only run if the temperature is over 70 degrees.

Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the Luup Intro page. To add Lua code to a scene, create the Scenes and click 'Luup scene'. You can also add Lua code to an event by clicking 'Luup event'. When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees Samples Dim switch #6 to 30%

Luup Lua extensions. In addition to the [Lua] commands described in the [Lua reference manual], you can also reference in your Lua code variables and functions from modules which the Luup engine provides as follows: Module: luup These are general purpose functions and variables. Call them by using the luup. module, such as: luup.log('Now running version: ' .. luup.version) variable: device The ID of this device instance, if it's running as part of a device variable: version, version_branch, version_major, version_minor version contains the version of the luup engine, such as "1.0.843", as a string. If( version_branch ~= 1 or version_major ~= 0 or version_minor < 843 ) then luup.log("I need version 1.0.843 minimum to run") return falseend variable: longitude Contains the longitude as a number, as found on the location tab in the setup UI. variable: latitude Contains the latitude as a number, as found on the location tab in the setup UI. variable: timezone variable: city variable: devices The members are: variable: rooms.

Lua Directory. This page is a top level directory of all Lua content at this wiki, grouped by topic. Introduction to Lua LearningLua - introduction to Lua (a guided directory) LuaTutorial - an informative tutorial written and reviewed by Lua users SampleCode - snippets of useful Lua code LuaComparison - how Lua compares with other languages. LuaFaq - unofficial, community-maintained frequently asked questions LuaLinks - a hand-edited list of useful Lua links LuaBooks - list of books on the subject of Lua Language Definition and Features LuaShortReference - concise summary of the Lua 5.1 syntax and core libraries LuaReferenceManualComments - user comments and annotations on the Lua Reference Manual. LuaSymbols? Tutorial:Networking with UDP - LOVE. This is an introduction to networking, using Luasocket. Don't run away!

Luasocket is compiled into LÖVE, and is really not that bad once you get used to it. This tutorial assumes that you are familiar with Callbacks, and Lua in general. Networking should be considered a moderately advanced topic. There two basic kinds of sockets, and we'll be covering UDP in this tutorial. UDP networking is message-oriented (as opposed to TCP being stream-oriented), meaning that its oriented around distinct (and otherwise independent) messages called datagrams. In the long run it pays to have a solid understanding on how networking works, but for now lets just get cracking. :3 We'll start with the LÖVE client, then follow up with a stand-alone server written in Lua.

The Client To start, we need to require the "socket" lib. socket provides low-level networking features. local socket =require"socket" -- the address and port of the serverlocal address, port = "localhost", 12345 love.load love.update And again! Luup UPNP Files. The following is the contents of the file Constants.h which defines the strings used for file device types, services, actions, variables, etc. /* Copyright (C) 2008 Mi Casa Verde, Inc., a Nevada Corporation All rights reserved.

This software may not be used or distributed without express consent. */ Device Types IR Device Types Device Files Device Categories Device Sub-Categories #define DEVICE_SUBCATEGORY_NONE 0 Lights #define DEVICE_SUBCATEGORY_INTERIOR 1 #define DEVICE_SUBCATEGORY_EXTERIOR 2 Climate #define DEVICE_SUBCATEGORY_HVAC 1 #define DEVICE_SUBCATEGORY_HEATER 2 Security #define DEVICE_SUBCATEGORY_DOOR 1 #define DEVICE_SUBCATEGORY_LEAK 2 #define DEVICE_SUBCATEGORY_MOTION 3 #define DEVICE_SUBCATEGORY_SMOKE 4 #define DEVICE_SUBCATEGORY_CO 5 #define DEVICE_SUBCATEGORY_GLASS 6 Window covering #define DEVICE_SUBCATEGORY_WINDOW_COV 1 #define DEVICE_SUBCATEGORY_ZRTSI 2 #define DEVICE_SUBCATEGORY_IRT 1 #define DEVICE_SUBCATEGORY_USBUIRT 2 HaGateway Basic functionality for the gateway itself Variables.

Lua Unofficial FAQ (uFAQ) LuaSocketShortRef20.pdf (application/pdf-objekt) Sample Code. 5.2 Reference Manual - contents. LuaSocket: Introduction to the core. LuaSocket is a Lua extension library that is composed by two parts: a C core that provides support for the TCP and UDP transport layers, and a set of Lua modules that add support for the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and downloading files) protocols and other functionality commonly needed by applications that deal with the Internet. This introduction is about the C core. Communication in LuaSocket is performed via I/O objects. These can represent different network domains. Currently, support is provided for TCP and UDP, but nothing prevents other developers from implementing SSL, Local Domain, Pipes, File Descriptors etc.

I/O objects provide a standard interface to I/O across different domains and operating systems. The API design had two goals in mind. One of the simplifications is the receive pattern capability. Another advantage is the flexible timeout control mechanism. TCP (Transfer Control Protocol) is reliable stream protocol. Example: Support modules. Luup Lua extensions - MiOS.