mirror of
https://github.com/azerothcore/mod-ale
synced 2025-12-01 21:15:19 +08:00
feat: Add global bytecode cache for Eluna scripts (#293)
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
#include "LootMgr.h"
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <unordered_map>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -73,12 +76,28 @@ template<typename T> struct EventKey;
|
||||
template<typename T> struct EntryKey;
|
||||
template<typename T> struct UniqueObjectKey;
|
||||
|
||||
// Type definition for bytecode buffer
|
||||
typedef std::vector<uint8> BytecodeBuffer;
|
||||
|
||||
// Global bytecode cache entry
|
||||
struct GlobalCacheEntry
|
||||
{
|
||||
BytecodeBuffer bytecode;
|
||||
std::time_t last_modified;
|
||||
std::string filepath;
|
||||
|
||||
GlobalCacheEntry() : last_modified(0) {}
|
||||
GlobalCacheEntry(const BytecodeBuffer& code, std::time_t modTime, const std::string& path)
|
||||
: bytecode(code), last_modified(modTime), filepath(path) {}
|
||||
};
|
||||
|
||||
struct LuaScript
|
||||
{
|
||||
std::string fileext;
|
||||
std::string filename;
|
||||
std::string filepath;
|
||||
std::string modulepath;
|
||||
LuaScript() {}
|
||||
};
|
||||
|
||||
#define ELUNA_STATE_PTR "Eluna State Ptr"
|
||||
@@ -150,6 +169,18 @@ private:
|
||||
static void LoadScriptPaths();
|
||||
static void GetScripts(std::string path);
|
||||
static void AddScriptPath(std::string filename, const std::string& fullpath);
|
||||
static int LoadCompiledScript(lua_State* L, const std::string& filepath);
|
||||
static std::time_t GetFileModTime(const std::string& filepath);
|
||||
static std::time_t GetFileModTimeWithCache(const std::string& filepath);
|
||||
|
||||
// Global cache management
|
||||
static bool CompileScriptToGlobalCache(const std::string& filepath);
|
||||
static bool CompileMoonScriptToGlobalCache(const std::string& filepath);
|
||||
static int TryLoadFromGlobalCache(lua_State* L, const std::string& filepath);
|
||||
static int LoadScriptWithCache(lua_State* L, const std::string& filepath, bool isMoonScript, uint32* compiledCount = nullptr, uint32* cachedCount = nullptr);
|
||||
static void ClearGlobalCache();
|
||||
static void ClearTimestampCache();
|
||||
static size_t GetGlobalCacheSize();
|
||||
|
||||
static int StackTrace(lua_State *_L);
|
||||
static void Report(lua_State* _L);
|
||||
|
||||
Reference in New Issue
Block a user