Open BuxtonCalvin opened 5 years ago
After quite a bit of trial and error, including debugging with zbstudio, I was able to get the plugin running by removing all the functions from the implementation file and then pasting them into the lua file, and unescaping characters from the pasted code where the log showed errors. I'm sure this isn't what you intended, but for now it seems to solve the scope problems that I was getting.
Would you mind sharing your updated I and L files? I tried moving the functions into the Lua file but I can't seem to get the plugin to run correctly.
Yeah, I was only able to get partial functionality by moving the code to the lua file. The underlying issue seems to be that the lua file is manually loaded as a module in the implementation file:
_,pluginModule = pcall( require, PLUGIN_MODULE_NAME )
The lua file then becomes an object for the plugin as a whole, however, in doing so, the lua file cannot see the implementation file globals. I solved this by hard mapping the PFB table--where the system globals are stored. For example:
D = function( msg, ... ) luup.devices[6].environment.PFB.log( luup.devices[6].environment.PFB.LOGLEVEL.DEBUG1, msg, ... ) end
You would replace the '6' with whatever device you are using. I tried using lul_device and pdev for the device number but this too did not work. As well, this kluge only works on openLuup as far as I know. I have not tried to load the plugin on a vera. openLuups author insists that this is not an issue with openLuup, but I'm not familiar enough with lua scope philosophy to make a judgment on why the implementation file globals do not propagate across the scope of the plugin.
I'm getting the following error in openLuup v19.8.1
openLuup.context_switch:: ERROR: ./L_EchoBridge1.lua:45: attempt to index global 'PFB' (a nil value) openLuup.scheduler:: job aborted : ./L_EchoBridge1.lua:45: attempt to index global 'PFB' (a nil value)
I'm using your latest I*.xml, but this did not work with the older version either. OpenLuup sees the global (as shown in the console), but the value is nil. When I print "PFB" in the test window, it also shows nil. Should I move the PFB field declarations to the L*xml. I'm just not familiar enough with how the transition form I to L occurs to identify why this global is not populating.
Otherwise, the plugin does launch, and the console shows my PnP actions are there, waiting to be fired.