zs Object

The "zs" object is the core part of the integration between TeSSH and Lua. It is short for "zscript" and is used to reference various items with the zscript system, such as your normal TeSSH variables, aliases, triggers, etc.

As with any Lua object, the "zs" object has many different methods and properties. They are documented in the list on the left.

Technically, the "zs" object returns a "TeSSH Window Object" for the currently active window. You can retrieve the window object for another window using the "windows" table. For example, if you have a window named "test", you can do:

testwin = windows["test"]
testwin.echo("in test window")

and then use the "testwin" variable just as you would with the default "zs" object.

zScript Commands and Functions

By default, you can access any TeSSH zScript command or function directly from the "zs" window variable. For example:

zs.echo("hello world")

will display the test "hello world" in the current window (same as the Lua print command would).

However, there is a lot more going on behind the scenes here. When you called "echo", Lua actually checks to see if there is a zScript command with the same name. If a command isn't found, then Lua will check for a zScript function with the same name. And if the function isn't found, Lua will finally search for a Predefined Variable with the matching name.

So, for accessing most zScript commands and functions, you don't have to do anything special. For example, this would call the #MESSAGE command and display the current %time:

zs.message( "The time is: " .. zs.time())

Note that to call a zScript function, you still need to put () even if you don't have any arguments to pass. Also note that we are concatenating two Lua strings using .. just like you normally would. All of the zScript commands and functions work just like normal Lua commands and functions would.

If you run into a case where a command and function have the same name, you can force Lua to pick one or the other using the "cmd" or "func" methods. For example, zs.cmd.additem will call the #ADDITEM command, while zs.func.additem() will call the %additem function. To access a predefined variable with a given name, use the "sys" method. For example, zs.sys.module will return the current module name just like the %module pre-defined variable in zScript.

Accessing TeSSH variables

Accessing a zScript variable is very easy in Lua using the "var" method. Simply add the name of the variable after the "zs.var." For example, assuming you have a zScript variable called "myvar", you could access it's value within Lua using the syntax: zs.var.myvar

This is a normal Lua variable. You can assign a value to it and it will change the value stored in the main zScript variable (and save it to your session file). This is an important distinction: Normal Lua variables are not saved between sessions. Only zScript variables are saved between sessions.

Add comment

Login or register to post comments