v1.4.4
This commit is contained in:
commit
9c94d113d3
10260 changed files with 1237388 additions and 0 deletions
68
source/game/scripting/StarLuaRoot.hpp
Normal file
68
source/game/scripting/StarLuaRoot.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef STAR_LUA_ROOT_HPP
|
||||
#define STAR_LUA_ROOT_HPP
|
||||
|
||||
#include "StarThread.hpp"
|
||||
#include "StarLua.hpp"
|
||||
#include "StarRoot.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
STAR_CLASS(LuaRoot);
|
||||
|
||||
// Loads and caches lua scripts from assets. Automatically clears cache on
|
||||
// root reload. Uses an internal LuaEngine, so this and all contexts are meant
|
||||
// for single threaded access and have no locking.
|
||||
class LuaRoot {
|
||||
public:
|
||||
LuaRoot();
|
||||
~LuaRoot();
|
||||
|
||||
void loadScript(String const& assetPath);
|
||||
bool scriptLoaded(String const& assetPath) const;
|
||||
void unloadScript(String const& assetPath);
|
||||
|
||||
// A script context can be created from the combination of several scripts,
|
||||
// the functions / data in each script will be loaded in order, so that later
|
||||
// specified scripts will overwrite previous ones.
|
||||
//
|
||||
// The LuaContext that is returned will have its 'require' function
|
||||
// overloaded to take absolute asset paths and load that asset path as a lua
|
||||
// module, with protection from duplicate loading.
|
||||
LuaContext createContext(String const& script);
|
||||
LuaContext createContext(StringList const& scriptPaths = {});
|
||||
|
||||
void collectGarbage(Maybe<unsigned> steps = {});
|
||||
void setAutoGarbageCollection(bool autoGarbageColleciton);
|
||||
void tuneAutoGarbageCollection(float pause, float stepMultiplier);
|
||||
size_t luaMemoryUsage() const;
|
||||
|
||||
size_t scriptCacheMemoryUsage() const;
|
||||
void clearScriptCache() const;
|
||||
|
||||
LuaEngine& luaEngine() const;
|
||||
|
||||
private:
|
||||
class ScriptCache {
|
||||
public:
|
||||
void loadScript(LuaEngine& engine, String const& assetPath);
|
||||
bool scriptLoaded(String const& assetPath) const;
|
||||
void unloadScript(String const& assetPath);
|
||||
void clear();
|
||||
void loadContextScript(LuaContext& context, String const& assetPath);
|
||||
size_t memoryUsage() const;
|
||||
|
||||
private:
|
||||
mutable RecursiveMutex mutex;
|
||||
StringMap<ByteArray> scripts;
|
||||
};
|
||||
|
||||
LuaEnginePtr m_luaEngine;
|
||||
shared_ptr<ScriptCache> m_scriptCache;
|
||||
ListenerPtr m_rootReloadListener;
|
||||
|
||||
String m_storageDirectory;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue