lua-users home
lua-l archive

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


The following example shows, why I need boolean:

   false = 0
    true = 1

   function Complete(Parameter,Value)
   
      if Parameter==nil then
         Parameter=Value
      end
   
      return Parameter
   
   end


   function Test(Parameter1,Parameter2)

      Parameter2=Complete(Parameter2,true)

      print(Parameter1)
      print(Parameter2)

   end

   Test(3)        -- prints 3 1
   Test(3,nil)    -- prints 3 1

   Test(3,false)  -- prints 3 0
   Test(3,true)   -- prints 3 1


In this example if Parameter2 not given then it should be used the
default. Is it possible to give the parameter as a reference instead of
a copy? Then I could write much shorter: Complete(Parameter2,true)
instead of typing the variable name twice.

Its impossible to use "nil" or "not nil" for Parameter2 as a flag.
Because "nil" is interpreted as a non given parameter.

Thanks for any comments.

--
Markus