TextScriptInterpreter: Server basics¶
A TextScriptInterpreter is a plug-in server that runs a text buffer as a script.
Overview¶
When running scripts and macros, nexus uses script-interpreter servers. When presented with an unknown script it enumerates the servers until it finds one that recognizes the file, and then it passes control to the interpreter. When the script completes the interpreter returns an optional message. The script functions by querying ScriptQuery Overview interfaces to read state and firing commands to perform actions.
Headers¶
- ‘’’scripts (lx-scripts.hpp)’’’
‘’CLxImpl_TextScriptInterpreter’’
‘’CLxUser_Script’’
- ‘’’command (lx-command.hpp)’’’
‘’CLxUser_CommandService’’
- ‘’’value (lx-value.hpp)’’’
‘’CLxUser_Message’’
LXsSAV_DOSPATTERN – the DOS-format search string for finding appropriate script files (e.g. “*.pl”).
The plug-in server class derives from CLxImpl_TextScriptInterpreter, and exports the ILxTextScriptInterpreter interface.
TextScriptInterpreter::ValidateFileType()¶
The ValidateFileType() method is called to quickly check if a file matches this interpreter. This is meant to be fast, so typically interpreters use their name on the first line of the script as a key.
1 2 3 4 5 6 7 | LxResult
tsi_ValidateFileType (
ILxUnknownID script,
const char *firstList) LXx_OVERRIDE
{
if (!strstr (firstLine, "myscript"))
return LXe_SCRIPT_UNKNOWN;
|
1 2 | return LXe_OK;
}
|
TextScriptInterpreter::Run()¶
The Run() method executes the script. The text is read from the script object, and its contents interpreted. In this example it’s a very simple macro interpreter, executing each line as a command. If an error occurs it can be reported through the message object.
1 2 3 4 5 6 7 8 9 10 11 | LxResult
tsi_Run (
ILxUnknownID script,
int execFlags,
const char *args,
ILxUnknownID message) LXx_OVERRIDE
{
CLxUser_Script scr (script);
CLxUser_CommandService cmd_srv;
const char *buf, *line;
unsigned len;
|
1 | scr.GetBuffer (&buf, &size);
|
1 2 3 4 5 6 7 8 9 10 11 | while (line = get_next_line (buf, line)) {
rc = cmd_srv.ExecuteArgString (-1, LXiCTAG_NULL, line);
if (LXx_FAIL (rc)) {
CLxUser_Message msg (message);
msg.SetCode (LXe_WARNING);
msg.SetMsg ("mymessagetable", "myerrormessagekey");
return LXe_FAILED;
}
}
return LXe_OK;
}
|