У меня есть приложение на c ++, которое взаимодействует с файлами lua. У меня есть файл lua, который извлекает zip-файлы, который работает, когда я запускаю его с помощью SciTe или командной строки Lua. Но когда я пытаюсь запустить его из приложения на c ++, оно, похоже, не работает.
require "zip"
function ExtractZipFiles(zipFilename, destinationPath)
zipFile, err = zip.open(zipFilename)
-- iterate through each file insize the zip file
for file in zipFile:files() do
currentFile, err = zipFile:open(file.filename)
currentFileContents = currentFile:read("*a") -- read entire contents of current file
currentFile:close()
hBinaryOutput = io.open(destinationPath .. file.filename, "wb")
-- write current file inside zip to a file outside zip
if(hBinaryOutput)then
hBinaryOutput:write(currentFileContents)
hBinaryOutput:close()
end
end
zipFile:close()
end
-- Unit Test
ExtractZipFiles("SZProcessTests.zip", "Infections\\")
Если на компьютере установлена программа Lua, дважды щелкните файл lua, который он запускает, и файлы будут извлечены, как и ожидалось. Но это не сработает, если я попытаюсь запустить файл lua из C ++ следующим образом:
void CSZTestClientMessagesDlg::OnBtnExecute()
{
L = lua_open();
luaL_openlibs(L);
luaL_dofile(L, "ExtractZipFiles.lua");
lua_close(L);
return;
}