Module:SimpleArgs/doc

Jump to navigation Jump to search

This is the documentation page for Module:SimpleArgs

Use[edit source]

Used by other modules.

Lua error in Module:TNT at line 157: attempt to index field 'data' (a nil value).

Functions[edit source]

  • Args are the arguments from the current frame.
  • Where is the name/s or order of the parameter.
  • The * mark indicates that it is an optional parameter). If you do not want to assign an optional non-correlative value you can assign the nil value.
Example: number_function (Args, ParId, LimInf*, LimSup*) -> number_function (args, 1, nil, 12) will verify that the number is not greater than 12.
Obviously it would be correct -> number_function (args, 1), without any verification of the values of the numbers.
  • Str (ing): String
  • Num (ber): Number.
  • Int (teger): Integer
  • Pos(itive)Num/Int: Positive/Integer number.
  • ZeroOrPos Num / Int: Zero or positive/Integer number.
  • Char (acter): Character.
  • Tab (ble): Table.

Main[edit source]

  • GetArgs (frame, HandleError*, SameSize*) - Returns arguments and its number.
If HandleError == true -> Error.handle = true
If SameSize == true -> Error.samesize = true

Handling of errors[edit source]

  • Error = {
handle = false,
yes = false,
msg = ,
samesize = false,
}
  • MsgError (S)

If handle = false when there is an input error. Thus: Lua error: error.

If handle = true, then the programmer will put in his/her module codereturn with the error, thus return MsgError(), returning the message with the font of a lua error. So: error. Check parameter by parameter is made if an error is not detected.

  • The error is recorded in a variable.
  • It is recorded that an error has been found and thus no more errors are checked in the rest of the parameters.
  • At the end of the check and input of variables the programmer should write: if SA.Error.yes then return SA.MsgError() end (where SA is defined as local SA = require "Module:SimpleArgs").

If handle = true and samesize = true then the returned message will be bolded and red in font. Thus: error.

See the examples

Other[edit source]

  • p.ParamsSep = '/' - Variable used for next function.
  • ConcatParams (tab) - Used when a parameter has more one name for same parameter.

Numbers checking[edit source]

They return the number N if this number are correct, otherwise returns an error message.

  • CheckNum (N, ParId, LimInf, LimSup)
  • CheckNumIsInt (N, ParId, LimInf*, LimSup*)
  • CheckNumIsPos (N, ParId, LimInf*, LimSup*)
  • CheckNumIsZeroOrPos (N, ParId, LimSup*)

Check if strings are numbers[edit source]

They return a number if the string is a correct number, otherwise returns an error message.

  • CheckSIsNum (S, ParId, LimInf*, LimSup*)
  • CheckSIsInt (S, ParId, LimInf*, LimSup*)
  • CheckSIsPosInt (S, ParId, LimInf*, LimSup*)
  • CheckSIsZeroOrPosInt (S, ParId, LimSup*)

Values from specific parameters of the frame[edit source]

The functions with an initial R indicate that the parameter is required. They return the value of the requested type of the parameter if it is correct, otherwise they return an error message. See the examples in Module:SimpleArgs/Tests/SVals

Strings[edit source]

  • Str_Par (Args, ParId, Default*)
  • RStr_Par (Args, ParId, OKEmpty*)
  • Char_Par (Args, ParId, Pattern, Default*)
  • RChar_Par (Args, ParId, Pattern)
  • NulOrWhitespace_Par (Args, ParId)
  • StrChkTab_Par (Args, ParId, Tab, CaseSens*, Default*)
  • RStrChkTab_Par (Args, ParId, Tab, CaseSens*)
  • StrIdxChkTab_Par (Args, ParId, Tab, CaseSens*, Default*)
  • RStrIdxChkTab_Par (Args, ParId, Tab, CaseSens*)

Numbers[edit source]

  • Num_Par (Args, ParId, Default*, LimInf*, LimSup*)
  • RNum_Par (Args, ParId, LimInf*, LimSup*)
  • PosNum_Par (Args, ParId, Default*, LimInf*, LimSup*)
  • RPosNum_Par (Args, ParId, LimInf*, LimSup*)
  • ZeroOrPosNum_Par (Args, ParId, Default*, LimInf*, LimSup*)
  • RZeroOrPosNum_Par (Args, ParId, LimInf*, LimSup*)
  • Int_Par (Args, ParId, Default*, LimInf*, LimSup*)
  • RInt_Par (Args, ParId, LimInf*, LimSup*)
  • PosInt_Par (Args, ParId, Default*, LimInf*, LimSup*)
  • RPosInt_Par (Args, ParId, LimInf*, LimSup*)
  • ZeroOrPosInt_Par (Args, ParId, Default*, LimSup*)
  • RZeroOrPosInt_Par (Args, ParId, LimSup*)

Boolean[edit source]

  • Bool_Par (Args, ParId, Default*)
  • RBool_Par (Args, ParId, Default*)

Index from a list[edit source]

  • StrIdxChkTab (Args, ParId, CaseSens, Default, ...)
  • RStrIdxChkTab (Args, ParId, CaseSens, ...)
  • StrIdxChkTabE (Args, ParId, CaseSens, Default, ...)
  • RStrIdxChkTabE (Args, ParId, CaseSens, ...)

Tables of strings or numbers[edit source]

MinItemNum and MaxItemNum, indicate the minimum and maximum number of elements inserted in the table.

When any of the values is not assigned, it will be operated according to OnEmpty: 0: It will be included. 1: Will not be included. 2. It will trigger an error and its message.

From one parameter[edit source]

For the same parameter with elements separated by Sep. Example, with "Sep" = ":" and the parameter = "12 : 1 : 1.3" returns {12, 1, 1.3}

  • StrTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, OnEmpty*)
  • NumTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • PosNumTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • ZeroOrPosNumTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • IntTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • PosIntTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • ZeroOrPosIntTab_1Par (Args, ParId, Sep, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
Of several parameters[edit source]

The parameters can be:

  • A number, then it will take the parameters from the current parameter to the last parameter.
  • If it is a string, it must contain a $d that will be replaced by a correlative integer (from 1) until no parameter is found. Example: 'para $d', look for 'para 1', 'para 2', etc.
  • If it is a table, the same search will be done that the previous point for each one of the values. Example: {'para $d', param $d}, will search 'para 1' and 'param 1', then 'para 2' and 'param 2', etc.

The functions:

  • StrTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, OnEmpty*)
  • NumTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • PosNumTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • ZeroOrPosNumTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • IntTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • PosIntTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)
  • ZeroOrPosIntTab_NPar (Args, NArgs, ParId, MinItemNum*, MaxItemNum*, LimInf*, LimSup*, OnEmpty*)

See the examples in Module:SimpleArgs/Tests/SVals

External links[edit source]