Skip to content

Commit 04af516

Browse files
committed
Add YYObjectBase methods
- Added several YYObjectBase methods to internal structure access - ``Add`` creates and assigns a value to a named variable inside the object - ``IsExtensible`` checks if a value can be safely added - ``FindOrAllocValue`` returns the pointer to a named variable's slot
1 parent 1eee7c2 commit 04af516

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

YYToolkit/source/YYTK/Shared.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,63 @@ RValue& CInstance::operator[](
420420
return RValue(this).at(Element);
421421
}
422422

423-
RValue& YYTK::CInstance::at(
423+
RValue& CInstance::at(
424424
IN std::string_view Element
425425
)
426426
{
427427
return RValue(this).at(Element);
428-
}
428+
}
429+
430+
#if YYTK_DEFINE_INTERNAL
431+
bool YYObjectBase::Add(
432+
IN const char* Name,
433+
IN const RValue& Value,
434+
IN int Flags
435+
)
436+
{
437+
// Get the module interface
438+
YYTKInterface* module_interface = GetYYTKInterface();
439+
if (!module_interface)
440+
return false;
441+
442+
// Check if we have the needed function
443+
if (!module_interface->GetRunnerInterface().COPY_RValue)
444+
return false;
445+
446+
// Get the slot ID - this calls FindAlloc_Slot_From_Name
447+
int32_t variable_hash = 0;
448+
if (!AurieSuccess(module_interface->GetVariableSlot(this, Name, variable_hash)))
449+
return false;
450+
451+
// Get the RValue reference
452+
RValue& rv = this->InternalGetYYVarRef(variable_hash);
453+
454+
// Copy the RValue from our stuff into the struct
455+
module_interface->GetRunnerInterface().COPY_RValue(&rv, &Value);
456+
rv.m_Flags = Flags; // Make the behavior consistent with the actual func
457+
458+
return true;
459+
}
460+
461+
bool YYObjectBase::IsExtensible()
462+
{
463+
return this->m_Flags & 1;
464+
}
465+
466+
RValue* YYObjectBase::FindOrAllocValue(
467+
IN const char* Name
468+
)
469+
{
470+
// Get the interface
471+
YYTKInterface* module_interface = GetYYTKInterface();
472+
if (!module_interface)
473+
return nullptr;
474+
475+
// Get the slot ID - this calls FindAlloc_Slot_From_Name
476+
int32_t variable_hash = 0;
477+
if (!AurieSuccess(module_interface->GetVariableSlot(this, Name, variable_hash)))
478+
return nullptr;
479+
480+
return &this->InternalGetYYVarRef(variable_hash);
481+
}
482+
#endif // YYTK_DEFINE_INTERNAL

YYToolkit/source/YYTK/Shared.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,18 @@ namespace YYTK
23312331

23322332
virtual RValue* GetDispose() = 0;
23332333

2334+
bool Add(
2335+
IN const char* Name,
2336+
IN const RValue& Value,
2337+
IN int Flags
2338+
);
2339+
2340+
bool IsExtensible();
2341+
2342+
RValue* FindOrAllocValue(
2343+
IN const char* Name
2344+
);
2345+
23342346
YYObjectBase* m_Flink;
23352347
YYObjectBase* m_Blink;
23362348
YYObjectBase* m_Prototype;

0 commit comments

Comments
 (0)