Skip to main content

HScript

Kindclass
Packagepsychlua
Full namepsychlua.HScript
Sourcesource/psychlua/HScript.hx

Haxe/HScript host (CodenameCrew hscript-improved), in two flavours:

  • Embedded — one interpreter lazily created per Lua script so Lua mods can escape into Haxe through runHaxeCode / runHaxeFunction / addHaxeLibrary (see implement()). parentLua is the owning script.
  • Standalone — a first-class mod script loaded straight from a .hx or .hscript file, with no Lua parent. It mirrors FunkinLua / PythonScript: the engine discovers it in the usual script folders, registers it in PlayState.hscriptArray, runs its top-level code, then dispatches the same lifecycle hooks (onCreate, onBeatHit, ...) and control-flow sentinels (Function_Stop, ...).

Each instance owns its own Interp, so top-level variables and functions are private to that script. Scripts share state explicitly through game (the PlayState), PlayState.instance.variables (setVar/getVar) or the inter-script calls seeded by seedScriptApi().

Not to be confused with psychlua.HaxeScript, the separate host for data/states/<Name>.hx scripted states/substates (psychlua.StateScripts).

Public fields​

NameTypeStaticDefaultNotes
Function_StopDynamicyes"##PSYCHLUA_FUNCTIONSTOP"Sentinel values are intentionally the SAME strings as FunkinLua's so the existing ret != FunkinLua.Function_Stop checks keep working for HScript.
Function_ContinueDynamicyes"##PSYCHLUA_FUNCTIONCONTINUE"—
Function_StopLuaDynamicyes"##PSYCHLUA_FUNCTIONSTOPLUA"—
Function_StopAllDynamicyes"##PSYCHLUA_FUNCTIONSTOPLUA"—
parserParseryesnew Parser()—
interpInterpno——
variablesMap<String, Dynamic>no—property (get, never)
parentLuaFunkinLuano—#if LUA_ALLOWED · Owning Lua script in embedded mode; always null for standalone mods.
scriptNameStringno''Resolved file path for standalone scripts; the Lua parent's path when embedded.
modFolderStringnonull—
closedBoolnofalse—
standaloneBoolnofalsetrue when this interpreter was loaded from its own .hx/.hscript file.
lastCalledFunctionStringno''—
lastCalledScriptHScriptyesnull—
sandboxedBoolnofalseRuntime half of the softmod sandbox; standalone scripts only (embedded mode delegates to the Lua parent).
securityModNameStringnonull—
securityAllowlistArray<String>no[]—
customFunctionsMap<String, Dynamic>yes[]—
registeredFunctionsMap<String, Dynamic>yes[]—

Public methods​

get_variables​

function get_variables()

View source

isHScriptFile​

static function isHScriptFile(file:String):Bool

Whether file names a standalone HScript mod file (extension check is case-insensitive).

ParameterTypeDefault
fileString—

View source

scriptBaseName​

static function scriptBaseName(file:String):String

Logical script name used to deduplicate discovery: scripts/hud.hx and scripts/hud.hscript are the same script, so a higher-priority folder (or a .hx in the same folder) shadows the other spelling.

ParameterTypeDefault
fileString—

View source

registerFunction​

static function registerFunction(name:String, func:Dynamic):Void
ParameterTypeDefault
nameString—
funcDynamic—

View source

fromFile​

static function fromFile(scriptName:String, ?scriptCode:String):HScript

Load a standalone script from scriptName (a resolved path, or a Paths-relative key) without any Lua parent.

ParameterTypeDefault
scriptNameString—
scriptCode (optional)String—

View source

new (constructor)​

function new(parent:#if LUA_ALLOWED FunkinLua #else Dynamic #end, ?scriptName:String, ?scriptCode:String)

@param parent owning Lua script for embedded mode, or null together with scriptName to load a standalone .hx/.hscript mod file.

ParameterTypeDefault
parent#if LUA_ALLOWED FunkinLua #else Dynamic #end—
scriptName (optional)String—
scriptCode (optional)String—

View source

initHaxeModule​

static function initHaxeModule(parent:FunkinLua)

Only compiled when #if LUA_ALLOWED.

ParameterTypeDefault
parentFunkinLua—

View source

addLibrary​

function addLibrary(libName:String, libPackage:String = ''):Bool

Bring a host class into this script's scope under its short name. Returns whether a class was resolved; sandboxed scripts are refused privileged classes (see backend.ModSecurity).

ParameterTypeDefault
libNameString—
libPackage (optional)String''

View source

call​

function call(func:String, args:Array<Dynamic>):Dynamic

Call a function defined by the script (engine hooks land here).

ParameterTypeDefault
funcString—
argsArray<Dynamic>—

View source

set​

function set(variable:String, data:Dynamic)

Write a global into the script's scope (engine state, callbacks, ...).

ParameterTypeDefault
variableString—
dataDynamic—

View source

get​

function get(variable:String):Dynamic

Read a global back out of the script's scope, or null when unset.

ParameterTypeDefault
variableString—

View source

addLocalCallback​

function addLocalCallback(name:String, myFunction:Dynamic)
ParameterTypeDefault
nameString—
myFunctionDynamic—

View source

stop​

function stop()

View source

hxTrace​

function hxTrace(text:String, ignoreCheck:Bool = false, deprecated:Bool = false, color:FlxColor = FlxColor.WHITE)

Script-visible logging. Embedded mode forwards to the Lua parent's trace channel ( honouring luaDebugMode there); standalone mode writes to the PlayState debug text, gated by hscriptDebugMode exactly like luaTrace/pyTrace.

ParameterTypeDefault
textString—
ignoreCheck (optional)Boolfalse
deprecated (optional)Boolfalse
color (optional)FlxColorFlxColor.WHITE

View source

allowsSecurityRule​

function allowsSecurityRule(rule:String):Bool
ParameterTypeDefault
ruleString—

View source

allowClassAccess​

function allowClassAccess(className:String):Bool
ParameterTypeDefault
classNameString—

View source

reportSecurityRuntime​

function reportSecurityRuntime(capability:String, line:Int = 0):String

Log a runtime guard failure to both the mod console and process log.

ParameterTypeDefault
capabilityString—
line (optional)Int0

View source

reportSecurityFinding​

function reportSecurityFinding(context:String, finding:ScriptSecurityFinding):Void
ParameterTypeDefault
contextString—
findingScriptSecurityFinding—

View source

execute​

function execute(codeToRun:String, funcToRun:String = null, ?funcArgs:Array<Dynamic>):Dynamic

Only compiled when #if HSCRIPT_ALLOWED.

ParameterTypeDefault
codeToRunString—
funcToRun (optional)Stringnull
funcArgs (optional)Array<Dynamic>—

View source

executeFunction​

function executeFunction(funcToRun:String = null, funcArgs:Array<Dynamic>)

Only compiled when #if HSCRIPT_ALLOWED.

ParameterTypeDefault
funcToRun (optional)Stringnull
funcArgsArray<Dynamic>—

View source

implement​

static function implement(funk:FunkinLua)

Only compiled when #if LUA_ALLOWED.

ParameterTypeDefault
funkFunkinLua—

View source

Internals​

Private / internal members
FieldTypeStatic
_parsedCacheMap<String, Expr>no
_missingCallsMap<String, Bool>no
Method
function loadStandalone(scriptName:String, ?scriptCode:String)
static function preprocessHScriptCode(code:String):String
function seedInitialGlobals()
function seedScriptApi()
function getRunningScriptNames():Array<String>
function seedScope()
function resolveScriptVar(name:String):Dynamic
function getBoolVar(variable:String):Bool
function effectiveSandboxed():Bool
function effectiveAllowlist():Array<String>