Luup Declarations

From MiOS
Revision as of 19:56, 12 June 2009 by Micasaverde (Talk | contribs)

Jump to: navigation, search

When the Luup engine calls your Lua code it will pass your code some variables relevant to whatever the code is supposed to do. You can see how your code looks with the full function declarations by bringing up this page in a web browser: http://ip_of_vera:49451/data_request?id=lu_lua&DeviceNum=8

Here is a list of the variables that are passed to your Lua code, and also a list of what return values the Lua code should send back. The tag names are explained here: Luup_Plugins_ByHand#The_Luup_XML_implementation_file:

Contents

run

variables: lul_device is a number that is the device id. lul_settings is a table with all the arguments to the action.

return value: true or false where true means the function ran ok, false means it failed.

Sample, including the function/end lines which the Luup engine adds automatically:

function SetTarget_run(lul_device,lul_settings)
  lu_log('device: ' .. tostring(lul_device) .. ' value: ' .. tostring(lul_settings.newTargetValue))
  return false
end

job

variables: lul_device is a number that is the device id. lul_settings is a table with all the arguments to the action. lul_job is the id number of the job.

return value: return 2 values with the syntax return a,b. The first is the job status and is a number from 0-5, and the second is the timeout in seconds. See Luup_Plugins_ByHand#run.2Fjob.2Fincoming.2Ftimeout this for details.

Sample, including the function/end lines which the Luup engine adds automatically:

function SendProntoCode_job(lul_device,lul_settings,lul_job)
  lu_log('device: ' .. tostring(lul_device) .. ' value: ' .. tostring(lul_settings.newTargetValue) .. ' job ID#: ' .. lul_job)
  -- 5=job_WaitingForCallback
  -- and we'll wait 10 seconds for incoming data
  return 5,10 
end

incoming (job)

variables: same as for job above, plus lul_data which is a binary string with the data received

return value: return 3 values with the syntax return a,b,c. The first two are the same as with job, and the 3rd is a true or false indicating if the incoming data was intended for this job. See Luup_Plugins_ByHand#run.2Fjob.2Fincoming.2Ftimeout this for details.

Sample, including the function/end lines which the Luup engine adds automatically:

function SendProntoCode_incoming(lul_device,lul_settings,lul_job,lul_data)
  lu_log('device: ' .. tostring(lul_device) .. ' value: ' .. tostring(lul_settings.newTargetValue) .. ' job ID#: ' .. lul_job .. " received data: " .. lul_data)
  -- 4=jobDone
  -- nil = n/a on the timeout since the job is done
  -- true = the incoming data was for us
  return 4,nil,true
end

timeout

variables: same as for job above.

return value: same as for job above

incoming (general, not for a job)

variables: lul_device is a number that is the device id. lul_data is a binary string with the data received

return variables: none

Personal tools