Having problems with "luup.call_delay"

I am working on my own version of the “random lights while I am out” scene and am having a problem with luup.call_delay. I have tried the following in the luup test code box (device=0) and get an apparent success, but execution is not logged. I used the following

luup.log(“pre delay”)
fail=luup.call_delay(“luup.log”, 1, “test delay success”)
luup.log("delay call fail = "… fail)

Once I got the syntax correct, “fail” went from “-1” to 0, which I believe indicates success. However the “test delay success” never shows up in the log. I would appreciate anyone pointing out the obvious.

the first parameter to luup.call_delay() is the name of a Lua function to call after the delay.

but “luup.log” isn’t the name of the luup.log function! in Lua, luup.log means: _G["luup"]["log"], what you’re telling luup.call_delay() is to call _G["luup.log"] see the difference?

the ‘easy’ solution is to add a trivial function:

function mylog(s) luup.log(s) end

and call luup.call_delay(“mylog”, 1, “test delay success”)

another (cleaner) solution is to just provide a global name for luup.log:

mylog = luup.log
luup.call_delay("mylog", 1, "test delay success")

I have a problem with call_delay too.

Here is what I have in my lua file:

[code]function delayFunc()

luup.log("RFXtrx: delayFunc ", 50)
return 0

end[/code]

and in another function:

log("call_delay") luup.call_delay("delayFunc", 15, "test call delay")

I can find this error in the logs:

50 07/12/12 15:22:05.615 luup_log:203: RFXtrx: call_delay <0x2c151680>
01 07/12/12 15:22:20.100 LuaInterface::CallFunction_Timer-5 function delayFunc failed attempt to call a nil value <0x2d551680>

I have probably done a stupid error but I don’t see where…
If someone can help me.

If I try this code in “Test luup code”, it works:

[code]function delayFunc()

luup.log("delayFunc ", 50)
return 0

end

luup.call_delay(“delayFunc”, 15, “test call delay”)
return 0[/code]

So is there something special to do when the same code is included in a lua file (plugin) ?

Sorry, my problem is solved, I had to define the function directly in the implementation file.

Is the function being used in a .lua module that you’ve include into your I_*.xml file?

ie. not in the top level namespace?

If so, you might need to expose a wrapper function in your I_*.xml file and use the name of that function in your call to call_delay.

Oops, posted at the same time…

We are limited to a simple string as parameter for a delayed function ? :frowning:

@lolodomo

Yes. If you want to pass a table you can either use a function to serialize the table in a string and deserialize it in the called function, or use a global variable.