diff options
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/LuaState.cpp | 12 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 1 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 410 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 55 |
4 files changed, 430 insertions, 48 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 4c0dfa676..c9e7815ca 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -676,6 +676,18 @@ void cLuaState::Push(int a_Value) +void cLuaState::Push(long a_Value) +{ + ASSERT(IsValid()); + + tolua_pushnumber(m_LuaState, static_cast<lua_Number>(a_Value)); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(UInt32 a_Value) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 759fdc54f..269a10369 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -248,6 +248,7 @@ public: void Push(cLuaUDPEndpoint * a_UDPEndpoint); void Push(double a_Value); void Push(int a_Value); + void Push(long a_Value); void Push(const UInt32 a_Value); void Push(void * a_Ptr); void Push(std::chrono::milliseconds a_time); diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 3fc5b477c..7e6839fdf 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -482,8 +482,258 @@ cPluginLua * cManualBindings::GetLuaPlugin(lua_State * L) +static int tolua_cFile_ChangeFileExt(lua_State * tolua_S) +{ + // API signature: + // ChangeFileExt(string, string) -> string + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2, 3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + // Execute: + AString FileName, NewExt; + ASSERT(L.GetStackValues(2, FileName, NewExt)); + L.Push(cFile::ChangeFileExt(FileName, NewExt)); + return 1; +} + + + + + +static int tolua_cFile_Copy(lua_State * tolua_S) +{ + // API signature: + // cFile:Copy(string, string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2, 3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + // Execute: + AString SrcFile, DstFile; + ASSERT(L.GetStackValues(2, SrcFile, DstFile)); + L.Push(cFile::Copy(SrcFile, DstFile)); + return 1; +} + + + + + +static int tolua_cFile_CreateFolder(lua_State * tolua_S) +{ + // API signature: + // cFile:CreateFolder(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString FolderPath; + ASSERT(L.GetStackValues(2, FolderPath)); + L.Push(cFile::CreateFolder(FolderPath)); + return 1; +} + + + + + +static int tolua_cFile_CreateFolderRecursive(lua_State * tolua_S) +{ + // API signature: + // cFile:CreateFolderRecursive(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString FolderPath; + ASSERT(L.GetStackValues(2, FolderPath)); + L.Push(cFile::CreateFolderRecursive(FolderPath)); + return 1; +} + + + + + +static int tolua_cFile_Delete(lua_State * tolua_S) +{ + // API signature: + // cFile:Delete(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::Delete(Path)); + return 1; +} + + + + + +static int tolua_cFile_DeleteFile(lua_State * tolua_S) +{ + // API signature: + // cFile:DeleteFile(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::DeleteFile(Path)); + return 1; +} + + + + + +static int tolua_cFile_DeleteFolder(lua_State * tolua_S) +{ + // API signature: + // cFile:DeleteFolder(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::DeleteFolder(Path)); + return 1; +} + + + + + +static int tolua_cFile_DeleteFolderContents(lua_State * tolua_S) +{ + // API signature: + // cFile:DeleteFolderContents(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::DeleteFolderContents(Path)); + return 1; +} + + + + + +static int tolua_cFile_Exists(lua_State * tolua_S) +{ + // API signature: + // cFile:Exists(string) -> bool + + // Obsolete, use IsFile() or IsFolder() instead + cLuaState L(tolua_S); + LOGWARNING("cFile:Exists() is obsolete, use cFile:IsFolder() or cFile:IsFile() instead!"); + L.LogStackTrace(); + + // Check params: + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::Exists(Path)); + return 1; +} + + + + + static int tolua_cFile_GetFolderContents(lua_State * tolua_S) { + // API signature: + // cFile:GetFolderContents(string) -> {string, string, ...} + // Check params: cLuaState LuaState(tolua_S); if ( @@ -497,7 +747,7 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S) // Get params: AString Folder; - LuaState.GetStackValues(2, Folder); + ASSERT(LuaState.GetStackValues(2, Folder)); // Execute and push result: LuaState.Push(cFile::GetFolderContents(Folder)); @@ -508,8 +758,119 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S) +static int tolua_cFile_GetLastModificationTime(lua_State * tolua_S) +{ + // API signature: + // cFile:GetLastModificationTime(string) -> number + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::GetLastModificationTime(Path)); + return 1; +} + + + + + +static int tolua_cFile_GetSize(lua_State * tolua_S) +{ + // API signature: + // cFile:GetSize(string) -> number + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::GetSize(Path)); + return 1; +} + + + + + +static int tolua_cFile_IsFile(lua_State * tolua_S) +{ + // API signature: + // cFile:IsFile(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::IsFile(Path)); + return 1; +} + + + + + +static int tolua_cFile_IsFolder(lua_State * tolua_S) +{ + // API signature: + // cFile:IsFolder(string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Execute: + AString Path; + ASSERT(L.GetStackValues(2, Path)); + L.Push(cFile::IsFolder(Path)); + return 1; +} + + + + + static int tolua_cFile_ReadWholeFile(lua_State * tolua_S) { + // API signature: + // cFile:ReadWholeFile(string) -> string + // Check params: cLuaState LuaState(tolua_S); if ( @@ -523,7 +884,7 @@ static int tolua_cFile_ReadWholeFile(lua_State * tolua_S) // Get params: AString FileName; - LuaState.GetStackValues(2, FileName); + ASSERT(LuaState.GetStackValues(2, FileName)); // Execute and push result: LuaState.Push(cFile::ReadWholeFile(FileName)); @@ -534,6 +895,33 @@ static int tolua_cFile_ReadWholeFile(lua_State * tolua_S) +static int tolua_cFile_Rename(lua_State * tolua_S) +{ + // API signature: + // cFile:Rename(string, string) -> bool + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cFile") || + !L.CheckParamString(2, 3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + // Execute: + AString SrcPath, DstPath; + ASSERT(L.GetStackValues(2, SrcPath, DstPath)); + L.Push(cFile::Rename(SrcPath, DstPath)); + return 1; +} + + + + + static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) { // API function no longer available: @@ -2846,8 +3234,22 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cFile"); - tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents); - tolua_function(tolua_S, "ReadWholeFile", tolua_cFile_ReadWholeFile); + tolua_function(tolua_S, "ChangeFileExt", tolua_cFile_ChangeFileExt); + tolua_function(tolua_S, "Copy", tolua_cFile_Copy); + tolua_function(tolua_S, "CreateFolder", tolua_cFile_CreateFolder); + tolua_function(tolua_S, "CreateFolderRecursive", tolua_cFile_CreateFolderRecursive); + tolua_function(tolua_S, "Delete", tolua_cFile_Delete); + tolua_function(tolua_S, "DeleteFile", tolua_cFile_DeleteFile); + tolua_function(tolua_S, "DeleteFolder", tolua_cFile_DeleteFolder); + tolua_function(tolua_S, "DeleteFolderContents", tolua_cFile_DeleteFolderContents); + tolua_function(tolua_S, "Exists", tolua_cFile_Exists); + tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents); + tolua_function(tolua_S, "GetLastModificationTime", tolua_cFile_GetLastModificationTime); + tolua_function(tolua_S, "GetSize", tolua_cFile_GetSize); + tolua_function(tolua_S, "IsFile", tolua_cFile_IsFile); + tolua_function(tolua_S, "IsFolder", tolua_cFile_IsFolder); + tolua_function(tolua_S, "ReadWholeFile", tolua_cFile_ReadWholeFile); + tolua_function(tolua_S, "Rename", tolua_cFile_Rename); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cHopperEntity"); diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 6f8499611..ba80d7130 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -374,7 +374,6 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S) class cLuaWorldTask : - public cWorld::cTask, public cPluginLua::cResettable { public: @@ -384,11 +383,7 @@ public: { } -protected: - int m_FnRef; - - // cWorld::cTask overrides: - virtual void Run(cWorld & a_World) override + void Run(cWorld & a_World) { cCSLock Lock(m_CSPlugin); if (m_Plugin != nullptr) @@ -396,7 +391,10 @@ protected: m_Plugin->Call(m_FnRef, &a_World); } } -} ; + +protected: + int m_FnRef; +}; @@ -433,9 +431,9 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S) return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1"); } - auto task = std::make_shared<cLuaWorldTask>(*Plugin, FnRef); - Plugin->AddResettable(task); - self->QueueTask(task); + auto ResettableTask = std::make_shared<cLuaWorldTask>(*Plugin, FnRef); + Plugin->AddResettable(ResettableTask); + self->QueueTask(std::bind(&cLuaWorldTask::Run, ResettableTask, std::placeholders::_1)); return 0; } @@ -483,35 +481,6 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) -class cLuaScheduledWorldTask : - public cWorld::cTask, - public cPluginLua::cResettable -{ -public: - cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef) : - cPluginLua::cResettable(a_Plugin), - m_FnRef(a_FnRef) - { - } - -protected: - int m_FnRef; - - // cWorld::cTask overrides: - virtual void Run(cWorld & a_World) override - { - cCSLock Lock(m_CSPlugin); - if (m_Plugin != nullptr) - { - m_Plugin->Call(m_FnRef, &a_World); - } - } -}; - - - - - static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) { // Binding for cWorld::ScheduleTask @@ -548,11 +517,9 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1"); } - int DelayTicks = static_cast<int>(tolua_tonumber(tolua_S, 2, 0)); - - auto task = std::make_shared<cLuaScheduledWorldTask>(*Plugin, FnRef); - Plugin->AddResettable(task); - World->ScheduleTask(DelayTicks, static_cast<cWorld::cTaskPtr>(task)); + auto ResettableTask = std::make_shared<cLuaWorldTask>(*Plugin, FnRef); + Plugin->AddResettable(ResettableTask); + World->ScheduleTask(static_cast<int>(tolua_tonumber(tolua_S, 2, 0)), std::bind(&cLuaWorldTask::Run, ResettableTask, std::placeholders::_1)); return 0; } |