Livecode Wiki
Advertisement

The private keyword makes a function or command local to the script in which it is present.

Syntax:

private {command|function} handlerName parameterList

Parameters:

  • handlerName The name of the handler
  • parameterList A comma-delimited list of the parameters

Examples

private command someLocalCommand pParameter1, pParameter2
   -- do something
end someLocalCommand
private function someLocalFunction
  -- do something
end someLocalFunction

Use the private keyword to declare a function or command as local to the object whose script it is in and stop it being directly called by any other objects.

Whenever an implicit handler call is made (ie calling the handler simply by its name as opposed to using send or call), LiveCode will check the current script for a private handler before allowing the call to pass through the message path. If a private handler is found in the current script, it will be directly called.

Note: Attempting to compile a private handler containing a pass control structure will cause a compilation error because private handlers cannot be passed through the message path. The use of private handlers for functionality local to a particular object is recommended as it encourages better encapsulation and helps avoid problems with namespace pollution caused by multiple handlers in the message path with the same name.

Using private handlers when appropriate will also result in a performance gain as fewer messages are passed through the message path.

Note: Although it is also possible to use on when declaring a private handler this is not recommended as it implies that the handler is a message sent when some event occurs. As private handlers are not passed through the message path, this is incorrect and can make the code harder to understand. Please see the on control structure entry for more details.

See also: commands, functions, Messages, Setprop, Getprop

Advertisement