I am trying to use the LuaDate library within some Vera lua code. I have placed the lua module date.lua into cmh-ludl where, for the most part, it functions correctly. However, the following code runs fine in my Windows IDE (Zerobrane) but not in Vera (using the Lua test page)? I have checked that I am using the same date.lua module in both cases. The IDE is using Lua 5.1.
local date = require(“date”)
local dobj1 = date(“Jan-5-0001 10:30:15”)
local dobj2 = date(“Jan-5-0001 10:30:16”)
luup.log("dobj1 : " … tostring(dobj1))
if (dobj1 < dobj2) then
–luup.log(“dobj1 < dobj2”)
end
When the above code is run in vera, the following error is reported:
LuaInterface::StartEngine failed run: 0: attempt to compare two table values <0x2dd4d680>
01 01/12/13 18:57:54.207 JobHandler_LuaUPnP::RunLua failed
I haven’t delved into Lua meta tables yet but on the surface, it looks as if < operand in the date comparison statement is not finding the equivalent date metatable operation but I can’t understand why this would be different between the two environments?
I have just found that the following code works where I call the meta table directly? My understanding is that Lua should do this automatically?
local dobj1 = date(“Jan-5-0001 10:30:15”)
local dobj2 = date(“Jan-5-0001 10:30:16”)
local mt = getmetatable(dobj1)
------if (dobj1 < dobj2) then
if (mt.__lt(dobj1,dobj2)) then
luup.log(“dobj1 < dobj2”)
else
luup.log(“dobj1 >= dobj2”)
end
It’s also possible that the MiOS “re-implementation” of [tt]require()[/tt] is messed up in some manner. They currently substitute in their own require() method, so you’re not seeing the Lua one when you call that.
This was done so they could load Plugin files (compressed, encrypted, etc). To do this, they substituted in their own require(), instead of just augmenting it’s loaders list.
Hard to validate, but it’s another theory for you…
Florin normally helps out in the Programming section. You can likely PM him if you don’t get a regular forum response within a few [working] days.
Failing that, as long as you have a reasonably simple test-case, then you could also open a support ticket (via Vera) directly against them. They respond to those eventually (They’ve been working one with me since late November, but that’s been a major issue with a Beta)
The problem is very easy to repeat and the failure of Lua to provide re-direction via a meta table seems like a fundamental issue for the Lua environment.
I will wait a few days to see if MCVFlorin has a look at the problem via this post and raise a support note if he doesn’t.
I noticed that I get the same error as you only when I upload the date.lua file uncompressed. If I upload it compressed I get another error message. The overloaded require calls the original require first, and only if that fails it loads the code using our luup.require function, then calls the original require again. If you uploaded the file uncompressed, it’s very probable that the date.lua code didn’t pass through luup.require, and there’s another issue. Unfortunately I couldn’t find what.
I haven’t been uploading any of my lua modules in lzo format. Mainly, because I can just drag Luamodules into Vera from Windows where I have my Lua IDE using WinSCP. As per recommendations on the forum, I use file ‘include’ to place Lua code into the device implementation file which reduces updating of the xml files significantly and isolates most of my work to Lua modules. Given the ease with which this problem can be reproduced, should I raise an MCV support request?
Best Home Automation shopping experience. Shop at Ezlo!