Skip to content

feat(framework): the Lua API declared once, require and api_version - #25

Merged
sp00ktober merged 10 commits into
mainfrom
lua-api
Oct 1, 2026
Merged

sp00ktober merged 10 commits into
mainfrom
lua-api

Conversation

@sp00ktober

Copy link
Copy Markdown
Contributor

For sp00ktober/MHFU-ModKit#66.

  • One declaration, lua/meta/mhfu.d.lua (---@meta), covers the 80 bindings, their constants, and the types of the event contexts and em_* tables, each with a doc line. tools/lua_api.py renders the registered table from it. Drift fails the build:
    • a binding defined but not declared fails the compile (-Werror=missing-declarations);
    • one declared but not defined fails the link;
    • each constant is static_asserted against its C name.
  • LuaLS: .luarc.json at the root (Lua 5.4, no io/os/debug). The prelude is annotated in place and embedded with its annotation lines blanked. A new CI job runs a pinned lua-language-server --check over all shipped Lua.
  • require: Lua's package library with one searcher, for mods/lib/<name>.lua; C loading and path search are removed.
    • A library that was required and then changes is re-run in place.
    • After boot, a library that is not loaded yet is read only during gameplay.
  • mhfu.api_version is 1 and logged on VM ready.
  • Scripts sorted:
    • lua/lib/: _prelude.lua, and mhfu_port.lua, now a library (port = require("mhfu_port"); the _queue global is gone);
    • lua/tools/: cli_bridge.lua;
    • lua/examples/: action override, second monster, ported Brute.
  • Boot errors visible: held log lines are written right after the boot script load, so a compile error reaches framework.log without entering a quest.
  • Freecam's seven bindings leave the API until freecam is installed (Freecam: its own toggle, then install it and give it back its Lua API #24).

Documented as they are, not fixed here:

  • mhfu.player_pos returns the camera eye;
  • a second Lua handler on an event replaces the first.

Test plan

  • uv run pytest, pre-commit run --all-files, clean make -C framework, LuaLS clean
  • A binding declared but not defined, and one defined but not declared, each fail the build
  • PPSSPP cold boot, after approval:
    • api=1 appears on VM ready;
    • a broken script's error shows up in framework.log while in the village;
    • mhfu_port loads through require and hot-reloads;
    • each example runs in a Giadrome quest

🤖 Generated with Claude Code

sp00ktober and others added 10 commits September 30, 2026 22:43
lua/meta/mhfu.d.lua declares every binding; tools/lua_api.py renders the
registered table from it, and -Werror=missing-declarations makes the two
sides fail the build when they disagree. require reads mods/lib/ and
reloads a changed library in place; boot lines are written after the
script load. Freecam's bindings leave the API until it is installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mod does `local port = require("mhfu_port")` and `port.mod(name, fn)`,
which runs its setup at once; the mhfu.port global and the queue
bootstrap are gone. It refuses to load below api_version 1, and takes the
player entity, the species table and its struct offsets from mhfu.addr.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An action override on the executor, a second Tigrex through the ADD path, and a ported Brute
on mhfu_port, each tested in lupa against the declared API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mhfu.d.lua declares params, returns and one doc line per binding, with
classes for the event contexts and em_status/em_rule tables. The prelude
annotates its handles where the code lives (mhfu is a partial class there,
so no inject-field). Binding comments in lua_host point at the declaration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efuses

Live, the manifest's charge (2,8) bounced to (0,1) within a tick when
requested, and (1,4) parked in its last phase, so the example no longer
scripts a move; it shows the port loading and a brain that reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sp00ktober
sp00ktober merged commit 5a0ca1b into main Oct 1, 2026
5 checks passed
@sp00ktober
sp00ktober deleted the lua-api branch October 4, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant