From 2ac53b983d3e956512c1681a07d25f93311524fd Mon Sep 17 00:00:00 2001 From: TEDERIs Date: Wed, 18 Oct 2023 15:48:35 +0700 Subject: [PATCH] Add navSave fumction --- source/module/LuaBinding.cpp | 16 ++++++++++++++++ source/module/LuaBinding.h | 1 + source/module/Module.cpp | 1 + 3 files changed, 18 insertions(+) diff --git a/source/module/LuaBinding.cpp b/source/module/LuaBinding.cpp index 557f969..f001ddb 100644 --- a/source/module/LuaBinding.cpp +++ b/source/module/LuaBinding.cpp @@ -40,6 +40,22 @@ int LuaBinding::navLoad(lua_State* luaVM) return 1; } +int LuaBinding::navSave(lua_State* luaVM) +{ + if (lua_type(luaVM, 1) != LUA_TSTRING) { + lua_pushboolean(luaVM, false); + return 1; + } + + auto& navigation = Navigation::GetInstance(); + + const char* path = lua_tostring(luaVM, 1); + const bool result = navigation.Save(path); + + lua_pushboolean(luaVM, result); + return 1; +} + int LuaBinding::navFindPath(lua_State* luaVM) { if (lua_gettop(luaVM) != 6) { diff --git a/source/module/LuaBinding.h b/source/module/LuaBinding.h index 25f2f6d..727ca8e 100644 --- a/source/module/LuaBinding.h +++ b/source/module/LuaBinding.h @@ -13,6 +13,7 @@ class LuaBinding public: static int navState(lua_State* luaVM); static int navLoad(lua_State* luaVM); + static int navSave(lua_State* luaVM); static int navFindPath(lua_State* luaVM); static int navNearestPoint(lua_State* luaVM); static int navDump(lua_State* luaVM); diff --git a/source/module/Module.cpp b/source/module/Module.cpp index 9a0de44..9989755 100644 --- a/source/module/Module.cpp +++ b/source/module/Module.cpp @@ -28,6 +28,7 @@ MTAEXPORT void RegisterFunctions(lua_State* luaVM) { pModuleManager->RegisterFunction(luaVM, "navState", LuaBinding::navState); pModuleManager->RegisterFunction(luaVM, "navLoad", LuaBinding::navLoad); + pModuleManager->RegisterFunction(luaVM, "navSave", LuaBinding::navSave); pModuleManager->RegisterFunction(luaVM, "navFindPath", LuaBinding::navFindPath); pModuleManager->RegisterFunction(luaVM, "navNearestPoint", LuaBinding::navNearestPoint); pModuleManager->RegisterFunction(luaVM, "navDump", LuaBinding::navDump);