Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. /*++
  2. Copyright (c) The Binding of Isaac: Ascension Team
  3. Licensed under the MIT license.
  4.  
  5. Module Name:
  6. - Ascension.h
  7.  
  8. Abstract:
  9. - This file contains the source code to the Ascension Team's lua compiler
  10.   and extra useful data types, methods, and functions.
  11.  
  12. Author(s):
  13. - Shen Lee (xiang)
  14. --*/
  15.  
  16. #ifndef ASCENSION_DOT_H
  17. #define ASCENSION_DOT_H
  18.  
  19. #include <iostream>
  20. #include <fstream>
  21. #include <cstring>
  22. #include <string>
  23. #include <vector>
  24. #include <algorithm>
  25.  
  26. #define __VOLATILE
  27.  
  28. namespace Ascension
  29. {
  30.     namespace Lua
  31.     {
  32.         typedef struct LuaEngine
  33.         {
  34.             static __VOLATILE char* LE_Translate(const char* __script) noexcept;
  35.             static signed LE_Create(const char* __script, const char* __content) noexcept;
  36.             static signed LE_Execute(const char* __script) noexcept;
  37.             static signed LE_Delete(const char* __script) noexcept;
  38.         private:
  39.             static bool LE_Find(const char* __script) noexcept;
  40.         };
  41.  
  42.         // Translates native C/C++ code into valid Lua script
  43.         __VOLATILE char* LuaEngine::LE_Translate(const char* __script) noexcept
  44.         {
  45.             // Left empty until further development status is reached
  46.         }
  47.  
  48.         // Creates a Lua source file, with provided content
  49.         signed LuaEngine::LE_Create(const char* __script, const char* __content) noexcept
  50.         {
  51.             std::ofstream file;
  52.             file.open(__script, std::ios::out);
  53.  
  54.             while (file.is_open())
  55.             {
  56.                 file.write(__content, strlen(__content));
  57.                 file.close();
  58.                 return 0;
  59.             }
  60.             return -1;
  61.         }
  62.  
  63.         // Runs the given Lua file, using the system's default interpreter
  64.         signed LuaEngine::LE_Execute(const char* __script) noexcept
  65.         {
  66.             std::string script_str = static_cast<std::string>(__script);
  67.             if (LE_Find(__script))
  68.             {
  69.                 system(("lua " + script_str).c_str());
  70.                 return 0;
  71.             }
  72.             else
  73.             {
  74.                 return -1;
  75.             }
  76.             return -1;
  77.         }
  78.  
  79.         // Deletes the target Lua file from the disk
  80.         signed LuaEngine::LE_Delete(const char* __script) noexcept
  81.         {
  82.             if (LE_Find(__script))
  83.             {
  84.                 return (remove(__script) == 0 ? 0 : -1);
  85.             }
  86.             else
  87.             {
  88.                 return -1;
  89.             }
  90.             return -1;
  91.         }
  92.  
  93.         // Searches the given directory for the file
  94.         bool LuaEngine::LE_Find(const char* __script) noexcept
  95.         {
  96.             std::ofstream file;
  97.             file.open(__script, std::ios_base::in);
  98.             if (file.is_open())
  99.             {
  100.                 file.close();
  101.                 return true;
  102.             }
  103.             else
  104.             {
  105.                 return false;
  106.             }
  107.             return false;
  108.         }
  109.     } // namespace Lua
  110. } // namespace Ascension
  111.  
  112. #endif // ASCENSION_DOT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement