How do I use stacks with LiveCode Server?
The LiveCode Server product brings our english like language to the server environment. The server engine is a separate build of the LiveCode engine with specific syntax and functionality that makes it suitable for use in command-line contexts and, in particular, as a CGI processor.
This lesson will teach you how you can use stacks with LiveCode Server.
The LiveCode Server message path
The LiveCode Server engine supports loading stacks in a similar manner to that of the desktop engines. Stacks provide the programmer with an additional means to store data and manage code, allowing for improved scope and funciton name management. However, visual and graphical commands are not supported (e.g. export snapshot).
At start up, a 'Home' stack is created which serves as the container for the global script. This stack sits at the root of the message path and works in much the same way as the IDE home stack - it sits after all mainstacks in the message path, but before library stacks and backscripts. Global script execution begins with the main script file.
Using library stacks
To load a library stack use the start using command:
start using stack "<path to stack>"
As with the start using command in other environments, the libraryStack message will be sent to the newly loaded library stack and its the stack script of the will sit behind the Home stack.
Using go stack
The go stack command is also valid:
go stack "<path to stack>"
Here, the newly loaded stack will sit in front of the home stack and will be sent the standard initialisation messages (preopenstack, openstack etc).
Sending messages to stacks
You can also send messages directly to stacks using the following form:
send "<message name>" to stack "<path to stack>"
This will result in the handler <message name> of stack defined in <path to stack> being called.