Passing parameters to the library
In many cases you will want to use parameters in your library handlers.
Handler definitions have the form:
The parameter list is a comma separated list of parameters, each of which has the form
The parameter list describes the parameters which can be passed to the handler. Handlers must be called with the correct number of parameters.
An in parameter means that the value from the caller is copied to the parameter variable in the callee handler.
An out parameter means that no value is copied from the caller, and the value on exit of the callee handler is copied back to the caller on return.
An inout parameter means that the value from the caller is copied to the parameter variable in the callee handler on entry, and copied back out again on exit.
The type of parameter is optional, if no type is specified it is taken to be optional any meaning it can be of any type.
Adding a parameter to the sayHello handler
We want to update the sayHello handler to take a pName parameter, passed in when sayHello is called from LiveCode Script.
The pName parameter will be a String value, which we will use to construct and return a custom “Hello” string.
We will:
- Update the handler definition with an in String parameter, pName.
- Construct the String to be returned using the pName parameter.
- Return the constructed String.
Constructing a string in LCB uses the same syntax as LiveCode Script.
- & – concatenates 2 strings
- && – concatenates 2 strings with a space in between
Testing the parameter passing
Test that your library compiles and behaves correctly.
- Open the Extension Builder.
- Load the updated LCB file.
- Click the Test button.
- Execute ‘put sayHello(“Elanor”)’ in the Message Box.
The returned string, containing the passed string, is displayed in the Message Box.