mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
* 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]>
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#include "execution_context.h"
|
|
|
|
#include "enums.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
execution_context_h::execution_context_h(std::shared_ptr<executor::IExecutionContext> executionContext)
|
|
: m_executionContext(std::move(executionContext))
|
|
{
|
|
}
|
|
const std::shared_ptr<executor::IExecutionContext>& execution_context_h::getExecutionContext() const
|
|
{
|
|
return m_executionContext;
|
|
}
|
|
bool execution_context_h::isValid() const { return m_executionContext != nullptr; }
|
|
|
|
ADE_OBJ(l_ExecutionContext,
|
|
execution_context_h,
|
|
"execution_context",
|
|
"An execution context for asynchronous operations");
|
|
|
|
ADE_FUNC(determineState,
|
|
l_ExecutionContext,
|
|
nullptr,
|
|
"Determines the current state of the context.",
|
|
"enumeration",
|
|
"One of the CONTEXT_* enumerations")
|
|
{
|
|
execution_context_h* context = nullptr;
|
|
if (!ade_get_args(L, "o", l_ExecutionContext.GetPtr(&context))) {
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
if (!context->isValid()) {
|
|
return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_INVALID)));
|
|
}
|
|
|
|
const auto state = context->getExecutionContext()->determineContextState();
|
|
switch (state) {
|
|
case executor::IExecutionContext::State::Valid:
|
|
return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_VALID)));
|
|
case executor::IExecutionContext::State::Suspended:
|
|
return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_SUSPENDED)));
|
|
case executor::IExecutionContext::State::Invalid:
|
|
default:
|
|
return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_INVALID)));
|
|
}
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace scripting
|