Imported from InputWindy/Hiyajo (
Plugins/GameEngine/EngineCore/Script/AGENTS.md). Install upstream withnpx skills add InputWindy/Hiyajo --skill Script. Copyright stays with the author.
Script - Agent Entry
All AI agents must read this file before entering this plugin.
Purpose
Multi-language script host (FScriptSystem) + one backend per language (IScriptLanguage).
The host only does language registration / dispatch / lifecycle; VM details, type binding, and script paths all live inside each backend.
Architecture (strict)
FScriptSystem (host, `FScriptSystem::Get()` process-unique)
`- IScriptLanguage (abstract backend interface, `Script.h`)
|- FLuaLanguage - Lua backend (sol2, current default)
|- FPythonLanguage - Python backend (CPython embed + Scapix bridge, inside TestGame project)
`- FScriptCSharp - C# backend (planned: Mono + Scapix)
- Host has zero language knowledge:
RegisterLanguage(IScriptLanguage*)registers idempotently byGetName();GetActive()returns the first registered backend;DoFile/Call/LoadScript<>forward to the active backend. - Backends must manage their own lifecycle: host
InitializecallsInitialize(Argc, Argv, "Scripts")on each;Shutdownshuts them down symmetrically. - Language-neutral value = opaque
void*:GetState()/CallHandle(void*)/FTypeBinder = void(*)(void*)are all opaque; only the caller that knows the language type casts afterinclude <sol/sol.hpp>etc. - Lua binding macros (
MAHO_LUA_BIND_BEGIN/FIELD/METHOD_FN/BIND_END+MAHO_LUA_BIND_REGISTER) only generate sol2 code. They are Lua-backend-specific sugar; do not use them for other languages. - Host does not couple to project logic: script file loading and per-frame
OnUpdatedriving are host/project concerns; FScriptSystem only provides execution primitives. - Dependencies go only through
.cpluginDependencies;Script.hmust stay sol-free (sol2 appears only inPrivate/Script.cpp).
Known Issues / TODO
WARNING: Scapix generator does not support Chinese paths (verified 2026-08-26)
- Symptom: engine sits at
C:\Users\luchunyi01\Desktop\shujia\Hiyajo(contains Chineseshujia).scapix.exe(clang core, precompiledscapix_bin) reportserror: no such file or directorywhen parsing bridge headers; the Chinese chars are treated as GBK bytes -> generation fails -> MSBuild retries repeatedly, appearing as a "stuck build" (a pile of cmake/python processes with no CPU). - Verification: under an ASCII path (
C:\temp\scapix_test) scapix.exe generates all python/cs/java/js/objc bridge code fine; the Chinese path fails every time. - Impact: the
ScriptPythonbridge (scapix_bridge_headers) cannot build under a Chinese path. CurrentlyEnabled: falseinTestGame.cproject. - Candidate fixes:
- Move engine + project to a pure ASCII path (e.g.
C:\Maho) - complete fix. - In CMake, copy bridge headers to an ASCII temp dir for generation, copy products back - complex.
- Drop Scapix, hand-write bindings with pybind11 - lose auto-generation.
- Move engine + project to a pure ASCII path (e.g.
- Re-enable condition: only after the path becomes ASCII.
Python backend integration notes (for reference when restoring)
ScriptPython.cmake: cmodule (v2.3.0) ->find_package(Scapix)-> two target identities:ScriptPython.dll(host, exportsCreateLayerto the engine, excludes bridge headers)ScriptPythonBridge.pyd(ScapixPYBIND11_MODULE,scapix_bridge_headersas its own target)
- MSVC Debug embedding CPython:
pyconfig.hunder_DEBUGpragma-linkspythonXXX_d.lib(not in the official installer) -> usetarget_link_options /NODEFAULTLIB:python<M><m>_d.lib+ temporary#undef _DEBUGbefore including Python.h. - Host
Initializeimports the bridge module viaPyImport_ImportModule("ScriptPythonBridge"); bridge classes land in thetestgamenamespace.
Docs
- Follow root AGENTS.md