resonance 1.0.1
Loading...
Searching...
No Matches
scripthost.h File Reference
#include "os/hxstr.h"
Include dependency graph for scripthost.h:

Go to the source code of this file.

Functions

void RegisterScriptCallTemplates ()
 Register every script call template.
void GetPythonScriptHost ()
 Create the interpreter host on first use and run the master script.
void DestroyPythonScriptHost ()
 Destroy the interpreter host and clear the global.
void InvokeMasterInitScript ()
 Run the master script against the existing host.
void CallScriptTemplate (int nTemplate,...)
 Call one registered script template as a statement.
void RunScript (const HxStr &script)
 Run one piece of script text as a statement.
HxStr GetPythonErrorText ()
 Describe the pending Python error as text.

Variables

constexpr int kScriptTemplateAutoexec = 0xc9
 Identifier of the autoexec() call template, which Application::Run() invokes once the services exist.

Function Documentation

◆ RegisterScriptCallTemplates()

void RegisterScriptCallTemplates ( )

Register every script call template.

The routine registers 132 templates against integer identifiers, among them autoexec(), get_screen_config()[0], and level_list['s'].stage, plus the two exception messages for Application::Run() and Application::ExitInstance(). The European release drops the get_met_string('s') and get_met_stringList('s') templates and registers 130.

Ghidra address:
NTSC-U/C: 0x004016c8
Ghidra address:
PAL: 0x0043a1b0

◆ GetPythonScriptHost()

void GetPythonScriptHost ( )

Create the interpreter host on first use and run the master script.

The host is created with twelve bytes of storage, constructed, handed to PyShell::RunMasterInitScript(), and only then stored in g_pPyShell, so the master script runs against a host the global does not yet publish. Application::Run() invokes this for the creation.

The routine returns nothing. Its early exit and its creation path disagree about what the result register holds, so the value is scratch rather than a return.

Ghidra address:
NTSC-U/C: 0x0050d588
Ghidra address:
PAL: 0x0054ca40

◆ DestroyPythonScriptHost()

void DestroyPythonScriptHost ( )

Destroy the interpreter host and clear the global.

The destructor is inlined here rather than called, so the body repeats PyShell's teardown.

Ghidra address:
NTSC-U/C: 0x0050d608
Ghidra address:
PAL: 0x0054cac0

◆ InvokeMasterInitScript()

void InvokeMasterInitScript ( )

Run the master script against the existing host.

A second entry point onto PyShell::RunMasterInitScript(), separate from the one GetPythonScriptHost() takes during creation.

Ghidra address:
NTSC-U/C: 0x0050d698
Ghidra address:
PAL: 0x0054cb50

◆ CallScriptTemplate()

void CallScriptTemplate ( int nTemplate,
... )

Call one registered script template as a statement.

The identifier selects a template, and the remaining arguments fill its format placeholders. The formatted text runs with Py_file_input.

The routine is variadic, and the register homing in its prologue is not the only evidence for that. The homed block's address is passed on to the formatter as the argument list, which is what proves the arguments are read rather than merely reserved.

Parameters
nTemplateThe template identifier.
Ghidra address:
NTSC-U/C: 0x005099b0
Ghidra address:
PAL: 0x00548ca0

◆ RunScript()

void RunScript ( const HxStr & script)

Run one piece of script text as a statement.

The result is discarded. ScriptSink uses this for the text a ScriptMsg supplies.

Parameters
scriptThe text to run.
Ghidra address:
NTSC-U/C: 0x00509b00
Ghidra address:
PAL: 0x00548e28

◆ GetPythonErrorText()

HxStr GetPythonErrorText ( )

Describe the pending Python error as text.

The routine reports the error through PyShell::ReportError() with an empty context, which halts the machine, so the text it returns is unreachable on the normal path. The plain return is no python exception found. A std::exception escaping the report is caught and its what() text returned after the prefix python error: . The handler matches the type_info that 0x004ad6b8 builds for std::exception, and it calls the vtable entry at +0x10, the what() slot in the g++ 2.9x layout.

Returns
The text.
Ghidra address:
NTSC-U/C: 0x00508f30
Ghidra address:
PAL: 0x005480c8

Variable Documentation

◆ kScriptTemplateAutoexec

int kScriptTemplateAutoexec = 0xc9
constexpr

Identifier of the autoexec() call template, which Application::Run() invokes once the services exist.