Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Source/Scripting/Scripting/LuaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ namespace Scripting
if (StringUtils::BeginsWith(relativePathAsString, "API/") || StringUtils::BeginsWith(relativePathAsString, "Bootstrap/"))
continue;

if (!_developerMode && StringUtils::BeginsWith(relativePathAsString, "Editor/"))
continue;

std::string pathStr = path.string();
u32 depth = GetPathDepth(scriptBootstrapDirectoryAsString, pathStr);
paths.push_back({ depth, path });
Expand Down
11 changes: 11 additions & 0 deletions Source/Scripting/Scripting/LuaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ namespace Scripting
void SetDirty() { _isDirty = true; }
void ClearDirty() { _isDirty = false; }

// When false, scripts under {scriptDir}/Editor/ are excluded from the load.
bool IsDeveloperMode() const { return _developerMode; }
void SetDeveloperMode(bool enabled)
{
if (enabled == _developerMode)
return;
_developerMode = enabled;
SetDirty();
}

ZenithStateManager& GetZenithStateManager()
{
return _zenithStateManager;
Expand Down Expand Up @@ -57,6 +67,7 @@ namespace Scripting

private:
bool _isDirty = false;
bool _developerMode = true;

u64 _currentTick = 0;
u64 _lastRecompiledTick = 0;
Expand Down
26 changes: 25 additions & 1 deletion Source/Scripting/Scripting/LuaMethodTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@

namespace Scripting
{
// Per-entry filter for LuaMethodTable::Set: entries overlapping excludeFlags are skipped.
enum class LuaMethodFlags : u32
{
None = 0,
DeveloperOnly = 1 << 0,
};

inline constexpr LuaMethodFlags operator|(LuaMethodFlags a, LuaMethodFlags b)
{
return static_cast<LuaMethodFlags>(static_cast<u32>(a) | static_cast<u32>(b));
}
inline constexpr LuaMethodFlags operator&(LuaMethodFlags a, LuaMethodFlags b)
{
return static_cast<LuaMethodFlags>(static_cast<u32>(a) & static_cast<u32>(b));
}
inline constexpr bool HasAnyFlag(LuaMethodFlags value, LuaMethodFlags mask)
{
return (value & mask) != LuaMethodFlags::None;
}

template <typename UserDataType = void>
struct LuaRegister
{
public:
const char* name;
typename std::conditional<std::is_same_v<UserDataType, void>, i32(*)(Zenith*), i32(*)(Zenith*, UserDataType*)>::type func;
LuaMethodFlags flags = LuaMethodFlags::None;
};

template <typename UserDataType>
Expand Down Expand Up @@ -112,7 +133,7 @@ namespace Scripting
}

template <class MethodTableUserDataType, size_t N>
static void Set(Zenith* zenith, const LuaRegister<MethodTableUserDataType> (&methodTable)[N], const char* globalName = nullptr)
static void Set(Zenith* zenith, const LuaRegister<MethodTableUserDataType> (&methodTable)[N], const char* globalName = nullptr, LuaMethodFlags excludeFlags = LuaMethodFlags::None)
{
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");
constexpr bool isGlobal = std::is_same_v<UserDataType, void>;
Expand Down Expand Up @@ -147,6 +168,9 @@ namespace Scripting
{
const auto& method = methodTable[i];

if (HasAnyFlag(method.flags, excludeFlags))
continue;

lua_pushstring(zenith->state, method.name);

lua_pushlightuserdata(zenith->state, (void*)&method);
Expand Down
Loading