Skip to content

Commit

Permalink
Add direct access for global functions
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Aug 25, 2021
1 parent ce34101 commit b2c6dfc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/reverse/RTTIMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void RTTIMapper::Register()

RegisterSimpleTypes(luaState, luaGlobal);
RegisterDirectTypes(luaState, luaGlobal, pRtti);
RegisterDirectGlobals(luaGlobal, pRtti);
RegisterScriptAliases(luaGlobal, pRtti);
RegisterSpecialAccessors(luaState, luaGlobal);
}
Expand Down Expand Up @@ -120,6 +121,26 @@ void RTTIMapper::RegisterDirectTypes(sol::state& aLuaState, sol::table& aLuaGlob
});
}

void RTTIMapper::RegisterDirectGlobals(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti)
{
apRtti->funcs.for_each([&aLuaGlobal](RED4ext::CName aOrigName, RED4ext::CGlobalFunction* apFunc) {
const std::string cShortName = apFunc->shortName.ToString();
const FuncFlags cFlags = *(FuncFlags*)(&apFunc->flags);

if (aLuaGlobal[cShortName] == sol::nil && !cFlags.isExec)
{
const std::string cFullName = apFunc->fullName.ToString();
const auto cIsClassFunc = cFullName.find("::") != std::string::npos;
const auto cIsOperatorFunc = cShortName.find(";") != std::string::npos;

if (!cIsClassFunc && !cIsOperatorFunc)
{
aLuaGlobal[cShortName] = RTTIHelper::Get().ResolveFunction(cShortName);
}
}
});
}

void RTTIMapper::RegisterScriptAliases(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti)
{
apRtti->scriptToNative.for_each([&aLuaGlobal](RED4ext::CName aScriptName, RED4ext::CName aNativeName) {
Expand Down
23 changes: 23 additions & 0 deletions src/reverse/RTTIMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@ struct RTTIMapper

private:

struct FuncFlags
{
uint32_t isNative : 1; // 00
uint32_t isStatic : 1; // 01
uint32_t isFinal : 1; // 02
uint32_t isEvent : 1; // 03
uint32_t isExec : 1; // 04
uint32_t isUndefinedBody : 1; // 05 Unconfirmed (unset for scripted funcs without body)
uint32_t isTimer : 1; // 06 Unconfirmed
uint32_t isPrivate : 1; // 07
uint32_t isProtected : 1; // 08
uint32_t isPublic : 1; // 09
uint32_t b11 : 1; // 0A
uint32_t b12 : 1; // 0B
uint32_t b13 : 1; // 0C
uint32_t isConst : 1; // 0D
uint32_t isQuest : 1; // 0E
uint32_t isThreadsafe : 1; // 0F
uint32_t b16 : 16;
};
RED4EXT_ASSERT_SIZE(FuncFlags, 0x4);

void RegisterSimpleTypes(sol::state& aLuaState, sol::table& aLuaGlobal);
void RegisterDirectTypes(sol::state& aLuaState, sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti);
void RegisterDirectGlobals(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti);
void RegisterScriptAliases(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti);
void RegisterSpecialAccessors(sol::state& aLuaState, sol::table& aLuaGlobal);

Expand Down

0 comments on commit b2c6dfc

Please sign in to comment.