Files
fs2open.github.com/test/test_data/scripting/base/autoIsValid/data/scripts/test.lua
T
Goober5000andClaude Fable 5.1 37b0b6ea82 Standardize isValid across the Lua API by making the types auto-generate it (#7761)
* Automatically generate the isValid() Lua API function for handle types

If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically.  An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own.  The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Add ADE_OBJ_VALIDATOR for index-based Lua handles

Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ.  The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles.  The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid().  Add a validator to HudGauge while we're at it.

Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
2026-09-08 10:50:53 -04:00

17 lines
819 B
Lua

-- gamestate and gameevent handles have an isValid() C++ member but never had an explicit
-- ADE_FUNC(isValid, ...), so these exercise the automatically generated function.
local state = ba.GameStates["GS_STATE_MAIN_MENU"]
assert(type(state.isValid) == "function", "gamestate should expose isValid()")
assert(state:isValid() == true, "a real game state should be valid")
local badState = ba.GameStates[100000]
assert(badState:isValid() == false, "an out-of-range game state should be invalid")
local event = ba.GameEvents["GS_EVENT_MAIN_MENU"]
assert(type(event.isValid) == "function", "gameevent should expose isValid()")
assert(event:isValid() == true, "a real game event should be valid")
local badEvent = ba.GameEvents[100000]
assert(badEvent:isValid() == false, "an out-of-range game event should be invalid")