akbooer / openLuup

a pure-Lua open-source emulation of the Vera Luup environment
Apache License 2.0
41 stars 19 forks source link

Converting standalone module("xxxxx", package.seeall) .lua files, to work with openLuup #31

Open nodecentral opened 3 hours ago

nodecentral commented 3 hours ago

Hi @akbooer

As always thank you so much for your support, i’m a big fan of openLuup, and making more of a leap over to it from Vera, by porting all my standalone modules, which is a big migration piece, hence I was confused why it was not working…

To try and wrap all this up, once and for all.. 🤪

My existing standalone Vera modules (.lua) all begin with e.g. module("xxpushover", package.seeall) and it looks like for them to work in openLuup, I need to ..

(a) remove the opening module () reference, and replace it with e.g. local xxpushover = {}

My module file consists of both local values, and global functions

(b) the file must end it with a return statement e.g. return xxpushover

To make use of the global functions in the file, I need to add a require statement in my startup in the format of ‘ local xxpushover = require "xxpushover"’

I have done all of the above, reloaded luup, yet when i call the following

xxpushover.push_link("mysecretapicode", "openLuup Home Link Test", "Testing 1 2 3", 1, 'http://192.168.102.107/', "openLuup Home")

I still get the same attempt to index global 'xxpushover' (a nil value) error ?

nodecentral commented 3 hours ago

For additional clarity, I have a luup.log statement in each module to show it’s been read, so I know openLuup is seeing/reading the file..

I’ve also tried the following, (i) change all global functions in the file to local, and (ii) adding the longer return statement proposed before e.g.

return {
  push_file = push_file,
  push_basic = push_basic,
  push_link = push_link,
  push_html = push_html,
  push_mono = push_mono,
  push_specific = push_specific,
}

And still get the same attempt to index global 'xxpushover' (a nil value)

akbooer commented 3 hours ago

Sorry you're still having problems.

Can you confirm where and how you are trying to access these functions (scene Lua code, for example?)

email me one of your modified modules so that I can give it a go.

nodecentral commented 3 hours ago

Hi @akbooer, my update to an earlier post overlapped with your response.

I’m testing it via the Luup Test option in openLuup (console), and just running this..

xxpushover.push_link("mysecretapicode", "openLuup Home Link Test", "Testing 1 2 3", 1, 'http://192.168.102.107/', "openLuup Home")

nodecentral commented 3 hours ago

It’s not a complicated module , just a mix of local variables and global functions, I posted a simplified version in the other thread - > https://github.com/akbooer/MetOffice_DataHub/issues/1#issuecomment-2452664513

I’ve looked in the lua files you created in the openLuup folder, to try learn/replicate what I could, while mine pale in comparison, (I like how yours start with an ABOUT section etc. ) - so I’m scratching my head on this..

akbooer commented 1 hour ago

Testing in AltUI or openLuup Lua Test?

akbooer commented 22 minutes ago

Indeed, I’ve just tried this. It is a ‘feature’ of AltUI, that it does not run its test code in the same environment as the startup/scene code. It can’t because it’s run within its own plug-in environment which has no access to that.

openLuup, on the other hand, does this correctly, and you should find that things work from its own Lua Test environment.

So, since your initial modifications, it’s probably actually worked all the time, and should be fine to use in any scene code.

A learning exercise for both of us, so that’s good anyway.