mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 08:27:06 +00:00
Lua: Add GetPluginName, GetPluginPath
This commit is contained in:
@@ -37,12 +37,13 @@ public:
|
|||||||
~TLuaFile();
|
~TLuaFile();
|
||||||
void SetStopThread(bool StopThread) { mStopThread = StopThread; }
|
void SetStopThread(bool StopThread) { mStopThread = StopThread; }
|
||||||
TLuaEngine& Engine() { return mEngine; }
|
TLuaEngine& Engine() { return mEngine; }
|
||||||
[[nodiscard]] std::string GetPluginName() const;
|
std::string GetPluginPath() const;
|
||||||
[[nodiscard]] std::string GetFileName() const;
|
std::string GetPluginName() const;
|
||||||
[[nodiscard]] const lua_State* GetState() const;
|
std::string GetFileName() const;
|
||||||
[[nodiscard]] bool GetStopThread() const { return mStopThread; }
|
const lua_State* GetState() const;
|
||||||
[[nodiscard]] const TLuaEngine& Engine() const { return mEngine; }
|
bool GetStopThread() const { return mStopThread; }
|
||||||
[[nodiscard]] std::string GetRegistered(const std::string& Event) const;
|
const TLuaEngine& Engine() const { return mEngine; }
|
||||||
|
std::string GetRegistered(const std::string& Event) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TLuaEngine& mEngine;
|
TLuaEngine& mEngine;
|
||||||
|
|||||||
@@ -922,6 +922,31 @@ int lua_HttpsPOST(lua_State* L) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lua_GetPluginName(lua_State* L) {
|
||||||
|
auto MaybeFile = Engine().GetScript(L);
|
||||||
|
if (MaybeFile) {
|
||||||
|
lua_pushstring(L, MaybeFile.value().get().GetPluginName().c_str());
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
warn("no plugin associated with this state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int lua_GetPluginPath(lua_State* L) {
|
||||||
|
auto MaybeFile = Engine().GetScript(L);
|
||||||
|
if (MaybeFile) {
|
||||||
|
lua_pushstring(L, MaybeFile.value().get().GetPluginPath().c_str());
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
warn("no plugin associated with this state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int lua_Dump(lua_State* L) {
|
||||||
|
}
|
||||||
|
|
||||||
void TLuaFile::Load() {
|
void TLuaFile::Load() {
|
||||||
Assert(mLuaState);
|
Assert(mLuaState);
|
||||||
luaL_openlibs(mLuaState);
|
luaL_openlibs(mLuaState);
|
||||||
@@ -965,11 +990,14 @@ void TLuaFile::Load() {
|
|||||||
LuaTable::InsertFunction(mLuaState, "HttpsGET", lua_HttpsGET);
|
LuaTable::InsertFunction(mLuaState, "HttpsGET", lua_HttpsGET);
|
||||||
LuaTable::InsertFunction(mLuaState, "HttpsPOST", lua_HttpsPOST);
|
LuaTable::InsertFunction(mLuaState, "HttpsPOST", lua_HttpsPOST);
|
||||||
LuaTable::InsertFunction(mLuaState, "GetServerVersion", lua_GetServerVersion);
|
LuaTable::InsertFunction(mLuaState, "GetServerVersion", lua_GetServerVersion);
|
||||||
|
LuaTable::InsertFunction(mLuaState, "GetPluginName", lua_GetPluginName);
|
||||||
|
LuaTable::InsertFunction(mLuaState, "GetPluginPath", lua_GetPluginPath);
|
||||||
|
|
||||||
LuaTable::End(mLuaState, "MP");
|
LuaTable::End(mLuaState, "MP");
|
||||||
|
|
||||||
lua_register(mLuaState, "print", lua_Print);
|
lua_register(mLuaState, "print", lua_Print);
|
||||||
lua_register(mLuaState, "printRaw", lua_PrintRaw);
|
lua_register(mLuaState, "printRaw", lua_PrintRaw);
|
||||||
|
lua_register(mLuaState, "dump", lua_Dump);
|
||||||
lua_register(mLuaState, "exit", lua_ServerExit);
|
lua_register(mLuaState, "exit", lua_ServerExit);
|
||||||
if (!mConsole)
|
if (!mConsole)
|
||||||
Reload();
|
Reload();
|
||||||
@@ -1032,6 +1060,13 @@ TLuaFile::~TLuaFile() {
|
|||||||
lua_close(mLuaState);
|
lua_close(mLuaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TLuaFile::GetPluginPath() const {
|
||||||
|
auto path = fs::path(Application::Settings.Resource);
|
||||||
|
path /= "Server";
|
||||||
|
path /= mPluginName;
|
||||||
|
return path.string();
|
||||||
|
}
|
||||||
|
|
||||||
void SendError(TLuaEngine& Engine, lua_State* L, const std::string& msg) {
|
void SendError(TLuaEngine& Engine, lua_State* L, const std::string& msg) {
|
||||||
Assert(L);
|
Assert(L);
|
||||||
auto MaybeS = Engine.GetScript(L);
|
auto MaybeS = Engine.GetScript(L);
|
||||||
|
|||||||
Reference in New Issue
Block a user