Skip to content

Commit f7db572

Browse files
committed
Add a concept of Developer Mode for Luau
Add Developer Mode to LuaManager Add DeveloperOnly flag support to Luau method tables
1 parent 644e978 commit f7db572

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

Source/Scripting/Scripting/LuaManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ namespace Scripting
381381
if (StringUtils::BeginsWith(relativePathAsString, "API/") || StringUtils::BeginsWith(relativePathAsString, "Bootstrap/"))
382382
continue;
383383

384+
if (!_developerMode && StringUtils::BeginsWith(relativePathAsString, "Editor/"))
385+
continue;
386+
384387
std::string pathStr = path.string();
385388
u32 depth = GetPathDepth(scriptBootstrapDirectoryAsString, pathStr);
386389
paths.push_back({ depth, path });

Source/Scripting/Scripting/LuaManager.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ namespace Scripting
3030
void SetDirty() { _isDirty = true; }
3131
void ClearDirty() { _isDirty = false; }
3232

33+
// When false, scripts under {scriptDir}/Editor/ are excluded from the load.
34+
bool IsDeveloperMode() const { return _developerMode; }
35+
void SetDeveloperMode(bool enabled)
36+
{
37+
if (enabled == _developerMode)
38+
return;
39+
_developerMode = enabled;
40+
SetDirty();
41+
}
42+
3343
ZenithStateManager& GetZenithStateManager()
3444
{
3545
return _zenithStateManager;
@@ -57,6 +67,7 @@ namespace Scripting
5767

5868
private:
5969
bool _isDirty = false;
70+
bool _developerMode = true;
6071

6172
u64 _currentTick = 0;
6273
u64 _lastRecompiledTick = 0;

Source/Scripting/Scripting/LuaMethodTable.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,33 @@
1212

1313
namespace Scripting
1414
{
15+
// Per-entry filter for LuaMethodTable::Set: entries overlapping excludeFlags are skipped.
16+
enum class LuaMethodFlags : u32
17+
{
18+
None = 0,
19+
DeveloperOnly = 1 << 0,
20+
};
21+
22+
inline constexpr LuaMethodFlags operator|(LuaMethodFlags a, LuaMethodFlags b)
23+
{
24+
return static_cast<LuaMethodFlags>(static_cast<u32>(a) | static_cast<u32>(b));
25+
}
26+
inline constexpr LuaMethodFlags operator&(LuaMethodFlags a, LuaMethodFlags b)
27+
{
28+
return static_cast<LuaMethodFlags>(static_cast<u32>(a) & static_cast<u32>(b));
29+
}
30+
inline constexpr bool HasAnyFlag(LuaMethodFlags value, LuaMethodFlags mask)
31+
{
32+
return (value & mask) != LuaMethodFlags::None;
33+
}
34+
1535
template <typename UserDataType = void>
1636
struct LuaRegister
1737
{
1838
public:
1939
const char* name;
2040
typename std::conditional<std::is_same_v<UserDataType, void>, i32(*)(Zenith*), i32(*)(Zenith*, UserDataType*)>::type func;
41+
LuaMethodFlags flags = LuaMethodFlags::None;
2142
};
2243

2344
template <typename UserDataType>
@@ -112,7 +133,7 @@ namespace Scripting
112133
}
113134

114135
template <class MethodTableUserDataType, size_t N>
115-
static void Set(Zenith* zenith, const LuaRegister<MethodTableUserDataType> (&methodTable)[N], const char* globalName = nullptr)
136+
static void Set(Zenith* zenith, const LuaRegister<MethodTableUserDataType> (&methodTable)[N], const char* globalName = nullptr, LuaMethodFlags excludeFlags = LuaMethodFlags::None)
116137
{
117138
static_assert(std::is_same_v<UserDataType, void> || std::is_same_v<UserDataType, MethodTableUserDataType> || std::is_base_of_v<MethodTableUserDataType, UserDataType>, "LuaMetaTable::Set - LuaRegister's UserDataType must either match LuaMetaTable's UserDataType, be derived from it or be void");
118139
constexpr bool isGlobal = std::is_same_v<UserDataType, void>;
@@ -147,6 +168,9 @@ namespace Scripting
147168
{
148169
const auto& method = methodTable[i];
149170

171+
if (HasAnyFlag(method.flags, excludeFlags))
172+
continue;
173+
150174
lua_pushstring(zenith->state, method.name);
151175

152176
lua_pushlightuserdata(zenith->state, (void*)&method);

0 commit comments

Comments
 (0)