Passing Variables to Modules

So this is my first test at creating a separate code file that I can call from my startup script…

First, I create my file and upload it:

[code]module(“L_MyModule”, package.seeall)

function TestSendMail1()
luup.call_action(gtVSP.gsServiceSMTPNotification1, “SendEmail”, { Recipient_Name=“MyName”, Recipient_eMail="", Subject= “Test0”, Message=“Test0”}, gtVSP.giSMTPID)

function TestSendMail2(sName, sEmailAddress, sSubject, sBody)
luup.call_action(gtVSP.gsServiceSMTPNotification1, “SendEmail”, { Recipient_Name=sName, Recipient_eMail=sEmailAddress, Subject=sSubject, Message=sBody }, gtVSP.giSMTPID)

I then try to reference it:

[code]local test = require “L_MyModule”

test.TestSendMail2(“MyName”, “”, “Insided Subcode”, “Insided Subcode”)[/code]

Neither works. But if I do this:

test.TestSendMail1("MyName", "", "Insided Subcode", "Insided Subcode")

It sends me an email from my TestSendMail1 function correctly…? I’ve been trying to follow this:

Any help?

What you’re doing should work, but my guess is that you’ve been through a couple or more iterations as you develop the code?

The package will only get loaded the first time, and any subsequent module changes will not be in effect until you purge the module either by a luup reload, or by explicitly deleting the package from the loaded list.

package.loaded["L_MyModule"] = nil

…so, in effect, you’ve not been testing the source code you think you are testing.

I’m still having issues. It’s not consistent at all. I modified the two packages to match my first package with my email address and different messages hard coded, and it still doesn’t work. I run the function code directly and it works.

Here’s my package now (confirmed by redownloading to check):

module("L_MyModule", package.seeall)

function TestSendMail1()    
	luup.call_action(gtVSP.gsServiceSMTPNotification1, "SendEmail", { Recipient_Name="MyName", Recipient_eMail="", Subject= "Test0", Message="Test0"}, gtVSP.giSMTPID)		

function TestSendMail2(sName, sEmailAddress, sSubject, sBody)
     --luup.call_action(gtVSP.gsServiceSMTPNotification1, "SendEmail", { Recipient_Name=sName, Recipient_eMail=sEmailAddress, Subject=sSubject, Message=sBody }, gtVSP.giSMTPID)
	 luup.call_action(gtVSP.gsServiceSMTPNotification1, "SendEmail", { Recipient_Name="MyName", Recipient_eMail="", Subject= "Test1", Message="Test1"}, gtVSP.giSMTPID)	 

In the test window, I run:

package.loaded["L_MyModule"] = nil
local tester = require("L_MyModule")

tester.TestSendMail2("MyName", "", "Insided Subcode", "Insided Subcode")

I’ve even downloaded L_ALTUI.lua and L_ALTUI_LuaRunHandler.lua to compare my syntax to, and to me it seems to be correct. Any ideas? ???

I’m running this on a Veraplus with the newest updates applied (1.7.2044). Is there a way to find out what version of Lua is being used?

It’s Lua 5.1, it has to be. So many things would not work if it were different.

print (_VERSION)

…run in Lua Code Test will confirm.

What is gtVSP ?

gtVSP is my table of generic variables that I initiate at startup. I keep all of my ID’s, services, etc in there.

…and you’re sure that’s in scope within your module?

The table is created as the first line in the startup script:

gtVSP = {}	

It should be in scope since it is global.

I would suggest you start instrumenting the code by logging some key values and also checking the status of error returns from function calls.

Yeah, I figured. I’ll need to do that while I’m at home tonight or tomorrow night. I don’t have access to SSH to my internal address while at work.