lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


function Test_Read_Only_Properties(nDocID, strNoteID)
 
local nReadOnlyNote = Nc_Note_Flag_ReadOnly_Get(nDocID, strNoteID)
local nReadOnlyDoc = Nc_Doc_ReadOnly_Get(nDocID)

-- Declare these as locals
local strMessage
local bTerminate
 
if nReadOnlyNote == 0 and nReadOnlyDoc == 0 then
strMessage = "" -- both read/write
bTerminate = false
end
 
if nReadOnlyNote == 0 and nReadOnlyDoc == 1 then
strMessage = "ERROR: The document is read-only. Cannot make requested change(s). Terminating script. To proceed, open the Document Properties dialog and change its read-only setting. Then try again."
bTerminate = true
end
 
if nReadOnlyNote == 1 and nReadOnlyDoc == 0 then
strMessage = "ERROR: The note is read-only. Cannot make requested change(s). Terminating script. To proceed, open the Note Properties dialog and change its read-only setting. Then try again."
bTerminate = true
end
if nReadOnlyNote == 1 and nReadOnlyDoc == 1 then
strMessage = "ERROR: Both the document and note are read-only. Cannot make requested change(s). Terminating script. To proceed, open the Document Properties dialog and change its read-only setting. Open the Note Properties dialog and change its read-only setting. Then execute the script again."
bTerminate = true
end
 
return strMessage, bTerminate
 
end -- function
 



On 24 August 2014 15:05, Paul Merrell <marbux@gmail.com> wrote:
Hi, all,

After a couple of years now, I think I'm approaching an understanding
of Lua's variable scoping. But where I'm still at sea is in evading
the use of globals in an if block or loop inside a function. I feel
like I'm missing something basic. An example at
<https://gist.github.com/Marbux/961d5aa3244993e42cae>, which executes
but is a work in progress.

A function begins at line 43 and a series of if blocks at line 48.
The variables within each if block are globals. How might I refactor
my function so that the same variables are locals, if possible.

I've been working around this kind of problem by declaring the globals
as nils in the global environment. See function test at line 79. But
particularly with functions shared by multiple scripts, I'd like to
find a way around that.
'
Hopefully, this is just my ignorance showing. I'll appreciate any
enlightenment here.

Best regards,

Paul

Best regards,

Paul




--
[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this
message.]