Scripting 2.0: Lua Script Engine#249
Scripting 2.0: Lua Script Engine#249ProfLander wants to merge 76 commits intothemrdemonized:all-in-one-vs2022-wpofrom
Conversation
|
There we go - let me know if this is still beyond scope for modded exes. (Also, I note that the commit log mentions Lisp - that's a leftover from an early C implementation of Fennel, which is factored out in favor of strictly vanilla Lua-side compilation machinery by later commits.) |
|
Alright, let me know when you iron out all bugs |
|
After some direct testing with GAMMA - which went fine, didn't realize the log errors were part of base 😅 - and rooting out a couple of unlocalization issues with assistance from plyaka.egor on Discord, this branch is now ready for public testing. Equivalence Proofs Test Build Mediafire - Anomaly Scripting 2.0 RC7 Testing Guidelines Due to the necessity of testing against a variety of modlists, and the general complexity of X-Ray, avoiding false positives is critical. As such, testers are requested to adhere to the following guidelines:
|
Unconfirmed Issues... Known IssuesGAMMA... Individual Mods... Fixed IssuesGAMMARight click > Details in inventory results in an empty popup
Stack overflow crash in
|
|
I'd like to highlight one small detail:
That paid Lua Studio and X-Ray's Lua Studio are two different products. |
0ec2e0f to
abfe814
Compare
|
@Xottab-DUTY Interesting, thanks for the pointer; I've updated the PR text appropriately. On another note - do you think these changes would be of interest to OXR once finalized? I know it's early days yet, but figure it would be good to try and standardize around the parts that apply to non-Anomaly X-Ray if possible, since that would allow the resulting benefits to go beyond Anomaly's little corner of the ecosystem, and avoid further divergence from the more formal / active engine forks. Beyond the naturally-tricky differences in C++, I've made sure to separate Anomaly's concerns where I can - The one exception at present being the handling of the |
ad1a2d9 to
5036943
Compare
You can find part of the code related to Lua Studio in leaked X-Ray 2.0 code. But there's a backend part, which wasn't leaked. We should ask Dmitriy Iassenev about it, I guess :)) Yes, we're interested in standardization! |
7cde9b6 to
5036943
Compare
- Refactor Lua source composition around std::string - Now memory-safe - Fixes undefined behaviour that was hidden by Lua header padding - Improve structure of CScriptDialect family - Separated headers / implementation - Switch to by-value std::string patterns - Make CScriptDialect authoritative over wrapping and unlocalization - Implement lisp, lisp-macro dialects that compile to the corresponding Fennel constructs
- Now lives in the `CScriptDialect` header - Rewritten using `std::string` - Fixed old broken `.` separator behaviour - Now creates tables if they don't exist, and updates otherwise - Allows `foo.bar.script` and `foo.baz.script` to coexist independently
- Scripts now load into package.loaded instead of _G - `require` is now the first-class autoload mechanism - Renamed existing `lua` dialect to `wua` - Recaptured vanilla semantics via `wua` metaprogramming - Reimplemented `lua` dialect as idiomatic clean-namespace Lua - Refactor lisp dialects around clean namespaces
- Replaced dialect semantic with macro semantic - Offloaded non-wua macros to scripts
- Rename `CScriptMacros` to `CScriptCompiler` - Make authoritative over unlocalization data - Simplify `CScriptMacro` implementation
- Switch macro output from string to Lua function - Rewrite existing macros with Lua metaprogramming - Refactor lisp_macro loading to compile eagerly, populate `package.loaded` as well as fennel macro storage - Rewrite lisp macro to manipulate AST
- Move `CScriptProcess`, `CScriptThread` to Lua - Remove old Lua Studio hooks (LuaDkmDebugger covers this case directly in VS) - Cleanup respective `.cpp` / `.h` files - Privatize or remove remaining `CScriptEngine` members - Simplify public `CScriptEngine` load / run functions
- Fixes debug introspection of script paths
- Prevents breakage of `debug.dump` use cases
- Prevents injected values from appearing in key iterations, inadvertent infinite loops
5036943 to
30f75e8
Compare
7318881 to
7eaddb3
Compare
|
Progress update: After roughly a week of me testing in GAMMA and other users trying it with their own modlists, no verifiable Scripting 2.0 tracebacks have appeared in logs. I think it's as stable as it's going to get in terms of day-to-day play. However, there's a catch; I tested it with buttplug-anomaly (still the foremost example of doing wacky native library FFI in Anomaly scripts...) and found a corner-case where Which is to say, I need to give the sandbox its own non-
Ah, well that's a relief in some sense; I didn't want to rip out code we could potentially use, but if there are missing pieces then the cleanup is for the best.
Cool! A PR is probably a ways off, since I have a teetering tower of Anomaly woes to address in the meantime, but I'll endeavour to keep working with portability in mind. Any syntax / semantic breaks should be capturable in a prospective On a related note, I've been eyeing up OXR's submodules for Anomaly integration following #264 ( But, they're worth highlighting as an example of where this changeset could help, since one of its big motivators is being able to manipulate Lua's syntax and semantics (ex. to encode X-Ray's own hardcoded lang extensions) without needing to change any C/++. Fairly limited for now since Lua lacks a macro system, but I have my eye on MetaLua for achieving more elaborate transformations (ex. a macro-hygenic impl of our script unlocalizer) later down the line. |
|
peak modding |
Anomaly engine is using LuaJIT 2.0.4 since it was added in the Call of Chernobyl engine.
Oh, introducing new language features by patching LuaJIT directly is bad because it adds additional burden of supporting new code and merging with the upstream LuaJIT. And what's more important it breaks compatibility with other engines that don't have these patches applied. Also, did you considered Luau? Though, it's problematic, because some features that are actually used in Anomaly and addons are just removed from Luau for security reasons. |
These are the fundamental engine changes extracted from #240, minus the new features / extensions to existing ones / sweeping refactor of existing gamedata structure, and plus some additional refinement / compatibility work / cleanup.
The intent is to be its 'least controversial' subset, minimizing impact on existing gamedata, while reimplementing the script engine in Lua to reduce footprint, ease maintainability, and open the door to smoother and more extensive modding in the future.
Summary of Changes
Moved the bulk of the following classes into Lua:
CScriptEngineCScriptStorageCScriptEngineCScriptEngineCScriptProcess/CScriptThreadrun_script/run_stringcommands while in-gameStripped out legacy Lua Studio debugger integration
Premium Lua-specific IDE that retails for $30 from a Web 1.0 siteGeneralized script environment boot process
CScriptEngine:init.luainit.lua:printfunctionrequireand error-guardedloadstringbootmodulebootmodule:package.pathmachinerypackage.loadersscript.ltxCScriptEnginecommon scripts runnerscript.ltxinitializes:xr/compilerxr/luaamxxr/classesxr/compilerloadstringwith per-script dispatch.lualoader established ininit.luaby defaultxr/luaxr/compilerwith generalized X-Ray Lua specializations.scriptextensionpackageenvironment behaviour_Grequire+ metatable indirection againstpackage.loadedscriptsfolderlocal,require, andreturnwaitandwait_gamefrom vanilla_g.script.luascripts_G(i.e. the
init.luapassthrough compiler) for selective re-export.scriptscripts are sandboxedamxxr/luawith unlocalization supportxr/classesCScriptEngineclass registration functionalityExposed recursion-friendly filesystem listings to Lua
axr_main, MCM, etc.New
evalconsole commandrun_stringwith the new workingprintprimitiveprintCompatibility
These changes are intended to be seamless for existing mods, and have been tested against Vanilla, my own 3D Ballistics debug modlist, and GAMMA.
Thus far, Vanilla and the 3D Ballistics list work as expected.
GAMMA exhibits ~4 load-time errors for existing mods, so further refinement of
xr/luais necessary before this can be considered complete.