Warning
The following topics are only for very skilled livecode programmers, not for beginners. The majority of livecoders doesn't need to know how to code LCB, they can use group. |
LCB LiveCode Builder language[]
There are 2 types of extensions that you can create with LCB:
- libraries: a library can be used to extend set of commands and functions available. The public handlers in a library are added at the bottom of the message path.
- Widget: a widget is a custom control, it appears in the Tools palette and can be added in any stack or card.
Editor[]
The best editor to write an extension is Atom ( https://atom.io/ ), and then this package for Atom: https://atom.io/packages/language-livecode ; you can also use the Atom internal installer to install the package language-livecode. The result is the same.
Now you have an editor ready for LCB.
Creating a new library project[]
In order to create an extension, you need a directory containing just one file with the lcb extension. No other lcb file can be in the same directory.
Now create a new empty file called HelloWorldLib.lcb.
Writing code[]
We want to create a library. Library identifier are in the form like:
community.livecode.<user name>.<library name>
You can change also community.livecode with you domain like com.mysite.....
So we start with:
library community.livecode.myname.helloworld end library
Now we have to put inside a public handler, public handlers have the form of:
public handler <handlerName>(ParameterList) [ returns <returnType> ] end handler
so we change our code to:
library community.livecode.myname.helloworld public handler SayHello() return "Hello world!" end handler end library
We must also insert some mandatory metadata: title, author and version. So our code changes to:
library community.livecode.myname.helloworld metadata title is "Hello word example" metadata author is "myName mySurname" metadata version is "1.0.0" public handler SayHello() return "Hello world!" end handler end library
Compiling[]
Use Tools-> Extension Builder, open the folder and file containing your file using the button tin the top right.
- click package, so you can now errors
- click install
Now test it with this code in the message box:
put SayHello()
If you want to share the library just share the file with the lce extension created by the livecode builder. It's in the same folder of the lcb file.
Complex example[]
The LCB language is more strict than LC script, so you need to declare variable type. Let's see an example:
library community.livecode.myname.helloworld metadata title is "Hello word example" metadata author is "myName mySurname" metadata version is "1.0.1" public handler SayHello() return "Hello world!" end handler public handler AdditionTest(in tLeft as Number, in tRight as Number) returns Number return tLeft + tRight end handler end library
Documenting the library[]
To document you library, you need to create a file called api.lcdoc. Inside you can write the documentation in lcdoc format like this: https://github.com/livecode/livecode/blob/develop-8.2/docs/dictionary/command/accept.lcdoc