Handler Parameters?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sat Apr 08, 2006 6:04 am

Handler Parameters?

Post by netdzynr » Sat Mar 14, 2015 12:09 am

Can a handler accept multiple values?

It seems like it's only possible pass one value to a handler, or otherwise you need to declare your parameters/arguments as separate variables. Thanks for clarifying here.

Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Re: Handler Parameters?

Post by WaltBrown » Sat Mar 14, 2015 2:42 am

<Sorry, I didn't see the mailbox this was in...>
Last edited by WaltBrown on Sat Mar 14, 2015 8:56 pm, edited 1 time in total.
Walt Brown
Omnis traductor traditor

Livecode Staff Member
Livecode Staff Member
Posts: 1076
Joined: Thu Apr 11, 2013 11:27 am

Re: Handler Parameters?

Post by LCMark » Sat Mar 14, 2015 8:02 am

@netdznr: Can you clarify what you mean (in case you have encountered a bug)?

Handlers in LCB are a little different from LiveCode Script.

First of all, there is no distinction between commands and functions - there are just handlers. Handlers which don't return a value simply set the 'the result' to 'undefined' in the caller after execution. You can call handlers with as a command, or as a function:

Code: Select all

handler myHandler()
  get myHandler()
end handler
You can specify parameters in the same was as you can in LCS, but you can type the parameters, and also specify a mode:

Code: Select all

handler myHandler(in pInParam as Integer, out rOutParam as String, inout xInOutParam)
end handler
An 'in' parameter is the same as in LCS, the value from the caller is copied to the parameter variable when the handler is called.

An 'out' parameter doesn't exist in LCS. Instead, you are expected to put a value into an out parameter's variable during execution of the handler. When the handler finishes executing, this value is copied into the variable (or container) you passed to it.

An 'inout' parameter is a combination of both - the value is copied from the caller at the start of the handler, and the value in the parameter variable is copied back to the caller when the handler finishes.

One thing where LCB is a little more powerful than LCS at the moment, is that you can actually pass chunk expressions to out and inout variables:

Code: Select all

handler callMyHandler()
  variable tString
  put "Hello World" into tString
  myHandler(tString, char 1 to 5 of tString, char 6 to -1 of tString)
end handler
In this case, in myHandler, the pInParam variable will have value "Hello World", the rOutParam will have no value at the start, but will replace char 1 to 5 of tString with the value you place in it within the handler, and xInOutParam will have value " World" on entry, and whatever you change that to in the handler will be placed in char 6 to -1 of tString when the handler finishes.

So, yes, handlers (just as in LCS) can have as many parameters as you like - but you also have more options as to how parameters are passed.

Post Reply

Return to “LiveCode Builder”