rodecomp/Source/Script/NLuaState.cpp
ragnarok-clanker 3ef7788be7 Decompile fn_20939 (TreeSubMap::Clear)
Batch #11590 by cremane: 0 byte-identical, 1 confirmed by peer review.

- fn_20939 TreeSubMap::Clear: logic confirmed by peer review

Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-05 03:46:03 +00:00

76 lines
1.5 KiB
C++

#include "Script/NLuaState.h"
extern "C" {
#include <lauxlib.h>
#include <lua.h>
}
#include <utility>
// GLOBAL: gl_24849
void* g_entryQueueMgr = nullptr;
struct TreeSubNode {
TreeSubNode* left;
TreeSubNode* parent;
TreeSubNode* right;
char color;
char isnil;
};
struct TreeSubMap {
TreeSubNode* head;
unsigned int size;
void Clear() noexcept;
void EraseSubtree(TreeSubMap& al, TreeSubNode* node);
};
// OFFSET: 0x00CA4AE0
// FUNCTION: fn_20939
void TreeSubMap::Clear() noexcept {
TreeSubNode* head = this->head;
TreeSubNode* cur = head->parent;
while (cur->isnil == 0) {
this->EraseSubtree(*this, cur->right);
::operator delete(std::exchange(cur, cur->left), 0x18);
}
head->parent = head;
head->left = head;
head->right = head;
this->size = 0;
}
// OFFSET: 0x00CA4B60
// FUNCTION: fn_20940
void* sub_CA4B60() {
return g_entryQueueMgr;
}
// OFFSET: 0x00CA4CF0
// FUNCTION: fn_20941
NLuaState::NLuaState() : m_state(nullptr), m_isValid(false) {
this->m_state = luaL_newstate();
if (this->m_state != nullptr) {
this->m_isValid = true;
}
}
NLuaState::~NLuaState() {
if (this->m_state != nullptr) {
lua_close(this->m_state);
this->m_state = nullptr;
}
}
NLuaThread::NLuaThread(NLuaState& parent) : m_state(nullptr), m_isValid(false) {
this->m_state = lua_newthread(parent.m_state);
if (this->m_state != nullptr) {
this->m_isValid = true;
}
}
// OFFSET: 0x00CA4E80
// FUNCTION: fn_20944
NLuaThread::~NLuaThread() {
this->m_state = nullptr;
}